read lint errors tool

This commit is contained in:
Andrew Pareles
2025-04-12 14:06:05 -07:00
parent 1bc936c43e
commit a2892fa5a2
3 changed files with 69 additions and 23 deletions
@@ -211,6 +211,14 @@ export class ToolsService implements IToolsService {
return { queryStr, searchInFolder, isRegex, pageNumber }
},
read_lint_errors: (params: RawToolParamsObj) => {
const {
uri: uriUnknown,
} = params
const uri = validateURI(uriUnknown)
return { uri }
},
// ---
create_file_or_folder: (params: RawToolParamsObj) => {
@@ -322,6 +330,12 @@ export class ToolsService implements IToolsService {
return { result: { queryStr, uris, hasNextPage } }
},
read_lint_errors: async ({ uri }) => {
await timeout(1000)
const { lintErrors } = this._getLintErrors(uri)
return { result: { lintErrors } }
},
// ---
create_file_or_folder: async ({ uri, isFolder }) => {
@@ -359,20 +373,11 @@ export class ToolsService implements IToolsService {
editCodeService.interruptURIStreaming({ uri: diffZoneURI })
}
// at end, get lint errors
const lintErrorsPromise = applyDonePromise.then(async () => {
await timeout(500)
const lintErrors = this.markerService
.read({ resource: uri })
.map(l => ({
code: typeof l.code === 'string' ? l.code : l.code?.value || '',
message: l.message,
startLineNumber: l.startLineNumber,
endLineNumber: l.endLineNumber,
} satisfies LintErrorItem))
if (!lintErrors.length) return { lintErrors: null }
return { lintErrors, }
await timeout(2000)
const { lintErrors } = this._getLintErrors(uri)
return { lintErrors }
})
return { result: lintErrorsPromise, interruptTool }
@@ -386,7 +391,11 @@ export class ToolsService implements IToolsService {
const nextPageStr = (hasNextPage: boolean) => hasNextPage ? '\n\n(more on next page...)' : ''
const lintErrorsStr = (lintErrors: LintErrorItem[]) => lintErrors.map((e, i) => `Error ${i + 1}:\nLines Affected: ${e.startLineNumber}-${e.endLineNumber}\nError message:${e.message}`).join('\n\n')
const stringifyLintErrors = (lintErrors: LintErrorItem[]) => {
return lintErrors
.map((e, i) => `Error ${i + 1}:\nLines Affected: ${e.startLineNumber}-${e.endLineNumber}\nError message:${e.message}`)
.join('\n\n')
}
// given to the LLM after the call
this.stringOfResult = {
@@ -406,6 +415,11 @@ export class ToolsService implements IToolsService {
search_files: (params, result) => {
return result.uris.map(uri => uri.fsPath).join('\n') + nextPageStr(result.hasNextPage)
},
read_lint_errors: (params, result) => {
return result.lintErrors ?
stringifyLintErrors(result.lintErrors)
: 'No lint errors found.'
},
// ---
create_file_or_folder: (params, result) => {
return `URI ${params.uri.fsPath} successfully created.`
@@ -416,7 +430,7 @@ export class ToolsService implements IToolsService {
edit_file: (params, result) => {
const lintErrsString = (
this.voidSettingsService.state.globalSettings.includeToolLintErrors ?
(result.lintErrors ? ` Lint errors found after change:\n${lintErrorsStr(result.lintErrors)}.\nIf this is related to a change made while calling this tool, you might want to fix the error.`
(result.lintErrors ? ` Lint errors found after change:\n${stringifyLintErrors(result.lintErrors)}.\nIf this is related to a change made while calling this tool, you might want to fix the error.`
: ` No lint errors found.`)
: '')
@@ -454,6 +468,21 @@ export class ToolsService implements IToolsService {
}
private _getLintErrors(uri: URI): { lintErrors: LintErrorItem[] | null } {
const lintErrors = this.markerService
.read({ resource: uri })
.map(l => ({
code: typeof l.code === 'string' ? l.code : l.code?.value || '',
message: l.message,
startLineNumber: l.startLineNumber,
endLineNumber: l.endLineNumber,
} satisfies LintErrorItem))
if (!lintErrors.length) return { lintErrors: null }
return { lintErrors, }
}
}
registerSingleton(IToolsService, ToolsService, InstantiationType.Eager);
@@ -11,16 +11,17 @@ import { toolNamesThatRequireApproval } from '../toolsServiceTypes.js';
import { IVoidModelService } from '../voidModelService.js';
import { ChatMode } from '../voidSettingsTypes.js';
// this is just for ease of readability
// Triple backtick wrapper used throughout the prompts for code blocks
export const tripleTick = ['```', '```']
// Maximum limits for directory structure information
export const MAX_DIRSTR_CHARS_TOTAL_BEGINNING = 20_000
export const MAX_DIRSTR_CHARS_TOTAL_TOOL = 20_000
export const MAX_DIRSTR_RESULTS_TOTAL_BEGINNING = 100
export const MAX_DIRSTR_RESULTS_TOTAL_TOOL = 100
// Maximum character limits for prefix and suffix context
export const MAX_PREFIX_SUFFIX_CHARS = 20_000
@@ -70,7 +71,7 @@ export const voidTools = {
read_file: {
name: 'read_file',
description: `Returns file contents of a given URI.`,
description: `Returns full contents of a given file.`,
params: {
...uriParam('file'),
start_line: { description: 'Optional. Default is 1. Start reading on this line.' },
@@ -123,11 +124,19 @@ export const voidTools = {
},
},
read_lint_errors: {
name: 'read_lint_errors',
description: `Returns all lint errors on a given file.`,
params: {
...uriParam('file'),
},
},
// --- editing (create/delete) ---
create_file_or_folder: {
name: 'create_file_or_folder',
description: `Create a file or folder at the given path. To create a folder, ensure the path ends with a trailing slash.`,
description: `Create a file or folder at the given path. To create a folder, the path MUST end with a trailing slash.`,
params: {
...uriParam('file or folder'),
},
@@ -581,10 +590,16 @@ Instructions:
`
}
export const ctrlKStream_userMessage = ({ selection, prefix, suffix, instructions, fimTags, isOllamaFIM, language }: {
selection: string, prefix: string, suffix: string, instructions: string, fimTags: QuickEditFimTagsType, language: string,
isOllamaFIM: false, // we require this be false for clarity
}) => {
export const ctrlKStream_userMessage = ({
selection,
prefix,
suffix,
instructions,
// isOllamaFIM: false, // Remove unused variable
fimTags,
language }: {
selection: string, prefix: string, suffix: string, instructions: string, fimTags: QuickEditFimTagsType, language: string,
}) => {
const { preTag, sufTag, midTag } = fimTags
// prompt the model artifically on how to do FIM
@@ -28,6 +28,7 @@ export type ToolCallParams = {
'get_dir_structure': { rootURI: URI },
'search_pathnames_only': { queryStr: string, searchInFolder: string | null, pageNumber: number },
'search_files': { queryStr: string, isRegex: boolean, searchInFolder: URI | null, pageNumber: number },
'read_lint_errors': { uri: URI },
// ---
'edit_file': { uri: URI, changeDescription: string },
'create_file_or_folder': { uri: URI, isFolder: boolean },
@@ -43,6 +44,7 @@ export type ToolResultType = {
'get_dir_structure': { str: string, },
'search_pathnames_only': { uris: URI[], hasNextPage: boolean },
'search_files': { uris: URI[], hasNextPage: boolean },
'read_lint_errors': { lintErrors: LintErrorItem[] | null },
// ---
'edit_file': Promise<{ lintErrors: LintErrorItem[] | null }>,
'create_file_or_folder': {},