completions for prompt files
This commit is contained in:
parent
82e6a4beca
commit
94ee240dff
3 changed files with 91 additions and 0 deletions
|
|
@ -64,6 +64,16 @@
|
|||
".continuerc.json"
|
||||
],
|
||||
"id": "jsonc"
|
||||
},
|
||||
{
|
||||
"id": "promptLanguage",
|
||||
"extensions": [
|
||||
".prompt"
|
||||
],
|
||||
"aliases": [
|
||||
"Prompt Language"
|
||||
],
|
||||
"configuration": "./prompt-file-language-configuration.json"
|
||||
}
|
||||
],
|
||||
"configuration": {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { Telemetry } from "core/util/posthog";
|
|||
import * as vscode from "vscode";
|
||||
import { VsCodeExtension } from "../extension/VsCodeExtension";
|
||||
import registerQuickFixProvider from "../lang-server/codeActions";
|
||||
import { registerPromptFilesCompletionProvider } from "../lang-server/promptFileCompletions";
|
||||
import { getExtensionVersion } from "../util/util";
|
||||
import { VsCodeContinueApi } from "./api";
|
||||
import { setupInlineTips } from "./inlineTips";
|
||||
|
|
@ -14,6 +15,7 @@ export async function activateExtension(context: vscode.ExtensionContext) {
|
|||
|
||||
// Register commands and providers
|
||||
registerQuickFixProvider();
|
||||
registerPromptFilesCompletionProvider(context);
|
||||
setupInlineTips(context);
|
||||
|
||||
const vscodeExtension = new VsCodeExtension(context);
|
||||
|
|
|
|||
79
extensions/vscode/src/lang-server/promptFileCompletions.ts
Normal file
79
extensions/vscode/src/lang-server/promptFileCompletions.ts
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
import { getBasename, getLastNPathParts } from "core/util";
|
||||
import vscode from "vscode";
|
||||
|
||||
export function registerPromptFilesCompletionProvider(
|
||||
context: vscode.ExtensionContext,
|
||||
) {
|
||||
let provider = vscode.languages.registerCompletionItemProvider(
|
||||
"promptLanguage",
|
||||
{
|
||||
async provideCompletionItems(
|
||||
document: vscode.TextDocument,
|
||||
position: vscode.Position,
|
||||
token: vscode.CancellationToken,
|
||||
context: vscode.CompletionContext,
|
||||
) {
|
||||
const linePrefix = document
|
||||
.lineAt(position)
|
||||
.text.substr(0, position.character);
|
||||
|
||||
// Check if the last character typed is '@'
|
||||
if (!linePrefix.endsWith("@")) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const files = await vscode.workspace.findFiles("**/*");
|
||||
|
||||
// Provide completion items
|
||||
return [
|
||||
{
|
||||
label: "terminal",
|
||||
detail: "Contents of terminal",
|
||||
sortText: "...",
|
||||
},
|
||||
{
|
||||
label: "tree",
|
||||
detail: "File tree of workspace",
|
||||
sortText: "...",
|
||||
},
|
||||
{
|
||||
label: "open",
|
||||
detail: "All open files",
|
||||
sortText: "...",
|
||||
},
|
||||
{
|
||||
label: "os",
|
||||
detail: "Operating system information",
|
||||
sortText: "...",
|
||||
},
|
||||
{
|
||||
label: "problems",
|
||||
detail: "Problems in the current file",
|
||||
sortText: "...",
|
||||
},
|
||||
{
|
||||
label: "currentFile",
|
||||
detail: "Current file",
|
||||
sortText: "...",
|
||||
},
|
||||
{
|
||||
label: "repo-map",
|
||||
detail: "Map of files in your repo",
|
||||
sortText: "...",
|
||||
},
|
||||
...files.map((file) => {
|
||||
return {
|
||||
label: getBasename(file.path),
|
||||
detail: getLastNPathParts(file.path, 2),
|
||||
insertText: file.path,
|
||||
kind: vscode.CompletionItemKind.File,
|
||||
};
|
||||
}),
|
||||
];
|
||||
},
|
||||
},
|
||||
"@", // Trigger completion when '@' is typed
|
||||
);
|
||||
|
||||
context.subscriptions.push(provider);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue