diff --git a/core/util/index.ts b/core/util/index.ts index 8d506d34f..fb4a597df 100644 --- a/core/util/index.ts +++ b/core/util/index.ts @@ -1,3 +1,7 @@ +import { + ContextProviderExtras, + } from "../index.js"; + export function removeQuotesAndEscapes(output: string): string { output = output.trim(); @@ -167,6 +171,26 @@ export function splitPath(path: string, withRoot?: string): string[] { return parts; } +export function getRelativePath(filepath: string, workspaceDirs: string[]): string { + for (const workspaceDir of workspaceDirs) { + const filepathParts = splitPath(filepath); + const workspaceDirParts = splitPath(workspaceDir); + if (filepathParts.slice(0, workspaceDirParts.length).join('/') === workspaceDirParts.join('/')) { + return filepathParts.slice(workspaceDirParts.length).join('/'); + } + } + return splitPath(filepath).pop() ?? ''; // If the file is not in any of the workspaces, return the plain filename +} + +export function splitPath(path: string, withRoot?: string): string[] { + let parts = path.includes("/") ? path.split("/") : path.split("\\"); + if (withRoot !== undefined) { + const rootParts = splitPath(withRoot); + parts = parts.slice(rootParts.length - 1); + } + return parts; +} + export function getMarkdownLanguageTagForFile(filepath: string): string { const ext = filepath.split(".").pop(); switch (ext) { diff --git a/docs/docs/walkthroughs/tab-autocomplete.md b/docs/docs/walkthroughs/tab-autocomplete.md index 05e8df148..4790808d9 100644 --- a/docs/docs/walkthroughs/tab-autocomplete.md +++ b/docs/docs/walkthroughs/tab-autocomplete.md @@ -91,17 +91,18 @@ This is just another object like the ones in the `"models"` array of `config.jso This object allows you to customize the behavior of tab-autocomplete. The available options are: +- `disable`: Disable autocomplete (can also be done from IDE settings) +- `template`: An optional template string to be used for autocomplete. It will be rendered with the Mustache templating language, and is passed the 'prefix' and 'suffix' variables. (String) - `useCopyBuffer`: Determines whether the copy buffer will be considered when constructing the prompt. (Boolean) - `useSuffix`: Determines whether to use the file suffix in the prompt. (Boolean) - `maxPromptTokens`: The maximum number of prompt tokens to use. A smaller number will yield faster completions, but less context. (Number) -- `debounceDelay`: The delay in milliseconds before triggering autocomplete after a keystroke. (Number) -- `maxSuffixPercentage`: The maximum percentage of the prompt that can be dedicated to the suffix. (Number) - `prefixPercentage`: The percentage of the input that should be dedicated to the prefix. (Number) -- `template`: An optional template string to be used for autocomplete. It will be rendered with the Mustache templating language, and is passed the 'prefix' and 'suffix' variables. (String) +- `maxSuffixPercentage`: The maximum percentage of the prompt that can be dedicated to the suffix. (Number) +- `debounceDelay`: The delay in milliseconds before triggering autocomplete after a keystroke. (Number) - `multilineCompletions`: Whether to enable multiline completions ("always", "never", or "auto"). Defaults to "auto". - `useCache`: Whether to cache and reuse completions when the prompt is the same as a previous one. May be useful to disable for testing purposes. - `useOtherFiles`: Whether to include context from files outside of the current one. Turning this off should be expected to reduce the accuracy of completions, but might be good for testing. -- `disable`: Disable autocomplete (can also be done from IDE settings) +- `disableInFiles`: A list of glob patterns for files in which you want to disable tab autocomplete. ### Full example diff --git a/extensions/vscode/continue_rc_schema.json b/extensions/vscode/continue_rc_schema.json index d938b626e..f54a44e9c 100644 --- a/extensions/vscode/continue_rc_schema.json +++ b/extensions/vscode/continue_rc_schema.json @@ -278,10 +278,7 @@ "apiType": { "title": "Api Type", "markdownDescription": "OpenAI API type, either `openai` or `azure`", - "enum": [ - "openai", - "azure" - ] + "enum": ["openai", "azure"] }, "apiVersion": { "title": "Api Version", @@ -294,11 +291,7 @@ "type": "string" } }, - "required": [ - "title", - "provider", - "model" - ], + "required": ["title", "provider", "model"], "allOf": [ { "if": { @@ -308,9 +301,7 @@ } }, "not": { - "required": [ - "provider" - ] + "required": ["provider"] } }, "then": { @@ -337,48 +328,33 @@ ] } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { - "required": [ - "apiKey" - ] + "required": ["apiKey"] } }, { "if": { "properties": { "provider": { - "enum": [ - "huggingface-tgi", - "huggingface-inference-api" - ] + "enum": ["huggingface-tgi", "huggingface-inference-api"] } } }, "then": { - "required": [ - "apiBase" - ] + "required": ["apiBase"] }, - "required": [ - "provider" - ] + "required": ["provider"] }, { "if": { "properties": { "provider": { - "enum": [ - "openai" - ] + "enum": ["openai"] } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { "properties": { @@ -398,14 +374,10 @@ "if": { "properties": { "provider": { - "enum": [ - "cloudflare" - ] + "enum": ["cloudflare"] } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { "properties": { @@ -463,14 +435,10 @@ "if": { "properties": { "provider": { - "enum": [ - "openai" - ] + "enum": ["openai"] } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { "properties": { @@ -501,14 +469,10 @@ "if": { "properties": { "provider": { - "enum": [ - "replicate" - ] + "enum": ["replicate"] } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { "properties": { @@ -538,14 +502,10 @@ "if": { "properties": { "provider": { - "enum": [ - "free-trial" - ] + "enum": ["free-trial"] } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { "properties": { @@ -570,9 +530,7 @@ "if": { "properties": { "provider": { - "enum": [ - "openai" - ] + "enum": ["openai"] }, "apiType": { "not": { @@ -580,9 +538,7 @@ } } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { "properties": { @@ -640,14 +596,10 @@ "if": { "properties": { "provider": { - "enum": [ - "anthropic" - ] + "enum": ["anthropic"] } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { "properties": { @@ -675,22 +627,15 @@ "if": { "properties": { "provider": { - "enum": [ - "cohere" - ] + "enum": ["cohere"] } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { "properties": { "model": { - "enum": [ - "command-r", - "command-r-plus" - ] + "enum": ["command-r", "command-r-plus"] } } } @@ -699,14 +644,10 @@ "if": { "properties": { "provider": { - "enum": [ - "bedrock" - ] + "enum": ["bedrock"] } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { "properties": { @@ -731,14 +672,10 @@ "if": { "properties": { "provider": { - "enum": [ - "gemini" - ] + "enum": ["gemini"] } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { "properties": { @@ -757,14 +694,10 @@ "if": { "properties": { "provider": { - "enum": [ - "together" - ] + "enum": ["together"] } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { "properties": { @@ -798,14 +731,10 @@ "if": { "properties": { "provider": { - "enum": [ - "deepinfra" - ] + "enum": ["deepinfra"] } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { "properties": { @@ -828,9 +757,7 @@ ] } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { "properties": { @@ -876,14 +803,10 @@ "if": { "properties": { "provider": { - "enum": [ - "ollama" - ] + "enum": ["ollama"] } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { "properties": { @@ -931,14 +854,10 @@ "if": { "properties": { "provider": { - "enum": [ - "mistral" - ] + "enum": ["mistral"] } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { "properties": { @@ -959,14 +878,10 @@ "if": { "properties": { "provider": { - "enum": [ - "groq" - ] + "enum": ["groq"] } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { "properties": { @@ -987,21 +902,15 @@ "if": { "properties": { "provider": { - "enum": [ - "fireworks" - ] + "enum": ["fireworks"] } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { "properties": { "model": { - "enum": [ - "starcoder-7b" - ] + "enum": ["starcoder-7b"] } } } @@ -1013,30 +922,20 @@ "const": "azure" } }, - "required": [ - "apiType" - ] + "required": ["apiType"] }, "then": { - "required": [ - "engine", - "apiVersion", - "apiBase" - ] + "required": ["engine", "apiVersion", "apiBase"] } }, { "if": { "properties": { "provider": { - "enum": [ - "openai" - ] + "enum": ["openai"] } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { "properties": { @@ -1053,9 +952,7 @@ "const": "llamafile" } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { "properties": { @@ -1069,14 +966,10 @@ "if": { "properties": { "provider": { - "enum": [ - "text-gen-webui" - ] + "enum": ["text-gen-webui"] } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { "properties": { @@ -1090,14 +983,10 @@ "if": { "properties": { "provider": { - "enum": [ - "flowise" - ] + "enum": ["flowise"] } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { "properties": { @@ -1124,10 +1013,7 @@ "type": "string" } }, - "required": [ - "key", - "value" - ] + "required": ["key", "value"] } }, "additionalFlowiseConfiguration": { @@ -1146,10 +1032,7 @@ "description": "Configuration Property value" } }, - "required": [ - "key", - "value" - ] + "required": ["key", "value"] } }, "model": { @@ -1239,9 +1122,7 @@ "type": "string" } }, - "required": [ - "default" - ] + "required": ["default"] }, "SlashCommand": { "title": "SlashCommand", @@ -1300,9 +1181,7 @@ "if": { "properties": { "name": { - "enum": [ - "issue" - ] + "enum": ["issue"] } } }, @@ -1315,23 +1194,17 @@ "description": "Enter the URL of the GitHub repository for which you want to generate the issue." } }, - "required": [ - "repositoryUrl" - ] + "required": ["repositoryUrl"] } }, - "required": [ - "params" - ] + "required": ["params"] } }, { "if": { "properties": { "name": { - "enum": [ - "edit" - ] + "enum": ["edit"] } } }, @@ -1356,9 +1229,7 @@ "if": { "properties": { "name": { - "enum": [ - "share" - ] + "enum": ["share"] } } }, @@ -1376,10 +1247,7 @@ } } ], - "required": [ - "name", - "description" - ] + "required": ["name", "description"] }, "CustomCommand": { "title": "CustomCommand", @@ -1398,11 +1266,7 @@ "type": "string" } }, - "required": [ - "name", - "prompt", - "description" - ] + "required": ["name", "prompt", "description"] }, "ContextProviderWithParams": { "title": "ContextProviderWithParams", @@ -1475,9 +1339,7 @@ "if": { "properties": { "name": { - "enum": [ - "google" - ] + "enum": ["google"] } } }, @@ -1490,23 +1352,17 @@ "description": "Your API key for https://serper.dev in order to get Google search results" } }, - "required": [ - "serperApiKey" - ] + "required": ["serperApiKey"] } }, - "required": [ - "params" - ] + "required": ["params"] } }, { "if": { "properties": { "name": { - "enum": [ - "open" - ] + "enum": ["open"] } } }, @@ -1528,9 +1384,7 @@ "if": { "properties": { "name": { - "enum": [ - "issue" - ] + "enum": ["issue"] } } }, @@ -1559,37 +1413,24 @@ "type": { "type": "string", "description": "The type of issues to search for", - "enum": [ - "open", - "closed", - "all" - ] + "enum": ["open", "closed", "all"] } }, - "required": [ - "owner", - "repo" - ] + "required": ["owner", "repo"] } } }, - "required": [ - "repos" - ] + "required": ["repos"] } }, - "required": [ - "params" - ] + "required": ["params"] } }, { "if": { "properties": { "name": { - "enum": [ - "database" - ] + "enum": ["database"] } } }, @@ -1607,11 +1448,7 @@ "connection_type": { "type": "string", "description": "The type of database (e.g., 'postgres', 'mysql')", - "enum": [ - "postgres", - "mysql", - "sqlite" - ] + "enum": ["postgres", "mysql", "sqlite"] }, "connection": { "type": "object", @@ -1644,25 +1481,17 @@ "required": [] } }, - "required": [ - "name", - "type", - "connection" - ] + "required": ["name", "type", "connection"] } }, - "required": [ - "connections" - ] + "required": ["connections"] } }, { "if": { "properties": { "name": { - "enum": [ - "gitlab-mr" - ] + "enum": ["gitlab-mr"] } } }, @@ -1683,23 +1512,17 @@ "description": "If you have code selected, filters out comments that aren't related to the selection." } }, - "required": [ - "token" - ] + "required": ["token"] } }, - "required": [ - "params" - ] + "required": ["params"] } }, { "if": { "properties": { "name": { - "enum": [ - "jira" - ] + "enum": ["jira"] } } }, @@ -1745,24 +1568,17 @@ ] } }, - "required": [ - "domain", - "token" - ] + "required": ["domain", "token"] } }, - "required": [ - "params" - ] + "required": ["params"] } }, { "if": { "properties": { "name": { - "enum": [ - "http" - ] + "enum": ["http"] } } }, @@ -1775,24 +1591,17 @@ "description": "The HTTP endpoint of your context provider server." } }, - "required": [ - "url" - ] + "required": ["url"] } }, - "required": [ - "params" - ] + "required": ["params"] } }, { "if": { "properties": { "name": { - "enum": [ - "codebase", - "folder" - ] + "enum": ["codebase", "folder"] } } }, @@ -1827,9 +1636,7 @@ "if": { "properties": { "name": { - "enum": [ - "postgres" - ] + "enum": ["postgres"] } } }, @@ -1881,19 +1688,11 @@ } } }, - "required": [ - "host", - "port", - "user", - "password", - "database" - ] + "required": ["host", "port", "user", "password", "database"] } } ], - "required": [ - "name" - ] + "required": ["name"] }, "SerializedContinueConfig": { "title": "config.json", @@ -2045,46 +1844,32 @@ "$ref": "#/definitions/RequestOptions" } }, - "required": [ - "provider" - ], + "required": ["provider"], "allOf": [ { "if": { "properties": { "provider": { - "enum": [ - "cohere" - ] + "enum": ["cohere"] } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { - "required": [ - "apiKey" - ] + "required": ["apiKey"] } }, { "if": { "properties": { "provider": { - "enum": [ - "gemini" - ] + "enum": ["gemini"] } }, - "required": [ - "provider" - ] + "required": ["provider"] }, "then": { - "required": [ - "apiKey" - ] + "required": ["apiKey"] } } ] @@ -2095,33 +1880,22 @@ "type": "object", "properties": { "name": { - "enum": [ - "cohere", - "voyage", - "llm", - "free-trial" - ] + "enum": ["cohere", "voyage", "llm", "free-trial"] }, "params": { "type": "object" } }, - "required": [ - "name" - ], + "required": ["name"], "allOf": [ { "if": { "properties": { "name": { - "enum": [ - "cohere" - ] + "enum": ["cohere"] } }, - "required": [ - "name" - ] + "required": ["name"] }, "then": { "properties": { @@ -2143,9 +1917,7 @@ "type": "string" } }, - "required": [ - "apiKey" - ] + "required": ["apiKey"] } } } @@ -2154,14 +1926,10 @@ "if": { "properties": { "name": { - "enum": [ - "llm" - ] + "enum": ["llm"] } }, - "required": [ - "name" - ] + "required": ["name"] }, "then": { "properties": { @@ -2172,9 +1940,7 @@ "type": "string" } }, - "required": [ - "modelTitle" - ] + "required": ["modelTitle"] } } } @@ -2183,14 +1949,10 @@ "if": { "properties": { "name": { - "enum": [ - "voyage" - ] + "enum": ["voyage"] } }, - "required": [ - "name" - ] + "required": ["name"] }, "then": { "properties": { @@ -2201,14 +1963,10 @@ "type": "string" }, "model": { - "enum": [ - "rerank-lite-1" - ] + "enum": ["rerank-lite-1"] } }, - "required": [ - "apiKey" - ] + "required": ["apiKey"] } } } @@ -2264,11 +2022,7 @@ "description": "An optional template string to be used for autocomplete. It will be rendered with the Mustache templating language, and is passed the 'prefix' and 'suffix' variables." }, "multilineCompletions": { - "enum": [ - "always", - "never", - "auto" - ], + "enum": ["always", "never", "auto"], "description": "If set to true, Continue will only complete a single line at a time." }, "useCache": { @@ -2297,10 +2051,7 @@ "type": "object", "properties": { "codeBlockToolbarPosition": { - "enum": [ - "top", - "bottom" - ], + "enum": ["top", "bottom"], "default": "top", "description": "Whether to show the copy and apply code buttons at the top or bottom of code blocks in the sidebar." }, @@ -2317,9 +2068,7 @@ "defaultContext": { "type": "array", "items": { - "enum": [ - "activeFile" - ] + "enum": ["activeFile"] } }, "modelRoles": { @@ -2362,10 +2111,7 @@ }, "mergeBehavior": { "type": "string", - "enum": [ - "merge", - "overwrite" - ], + "enum": ["merge", "overwrite"], "default": "merge", "title": "Merge behavior", "markdownDescription": "If set to 'merge', .continuerc.json will be applied on top of config.json (arrays and objects are merged). If set to 'overwrite', then every top-level property of .continuerc.json will overwrite that property from config.json." @@ -2373,4 +2119,4 @@ } } } -} \ No newline at end of file +}