|
17 | 17 | import * as vscode from "vscode"; |
18 | 18 | import { SCOPES, ScopeClassification, getScopeMarkdown } from "./scopes.js"; |
19 | 19 |
|
| 20 | +export function scopeCompletion( |
| 21 | + document: vscode.TextDocument, |
| 22 | + position: vscode.Position, |
| 23 | +): vscode.CompletionItem[] { |
| 24 | + const completionItems: vscode.CompletionItem[] = []; |
| 25 | + |
| 26 | + const lineText = document.lineAt(position.line).text; |
| 27 | + const textBeforeCursor = lineText.substring(0, position.character); |
| 28 | + |
| 29 | + const match = textBeforeCursor.match( |
| 30 | + /(https:\/\/www\.googleapis\.com\/auth\/[a-zA-Z._-]*)$/, |
| 31 | + ); |
| 32 | + |
| 33 | + if (!match) { |
| 34 | + return completionItems; |
| 35 | + } |
| 36 | + |
| 37 | + for (const [scope] of SCOPES.entries()) { |
| 38 | + if (scope.startsWith(match[1])) { |
| 39 | + const item = new vscode.CompletionItem(scope.split("/").pop() ?? scope); |
| 40 | + item.insertText = scope.replace(match[1], ""); |
| 41 | + completionItems.push(item); |
| 42 | + } |
| 43 | + } |
| 44 | + return completionItems.sort((a, b) => |
| 45 | + String(a.label).localeCompare(String(b.label)), |
| 46 | + ); |
| 47 | +} |
| 48 | + |
20 | 49 | export function activate(context: vscode.ExtensionContext) { |
21 | 50 | if (vscode.lm.registerMcpServerDefinitionProvider) { |
22 | 51 | context.subscriptions.push( |
@@ -77,6 +106,20 @@ export function activate(context: vscode.ExtensionContext) { |
77 | 106 | vscode.languages.createDiagnosticCollection("scopes"); |
78 | 107 | context.subscriptions.push(scopeDiagnostics); |
79 | 108 |
|
| 109 | + const scopeCompletionProvider = |
| 110 | + vscode.languages.registerCompletionItemProvider( |
| 111 | + { scheme: "file" }, |
| 112 | + { |
| 113 | + provideCompletionItems(document, position) { |
| 114 | + console.log(position); |
| 115 | + return scopeCompletion(document, position); |
| 116 | + }, |
| 117 | + }, |
| 118 | + "/", |
| 119 | + ".", |
| 120 | + ); |
| 121 | + context.subscriptions.push(scopeCompletionProvider); |
| 122 | + |
80 | 123 | function updateDiagnostics( |
81 | 124 | document: vscode.TextDocument, |
82 | 125 | collection: vscode.DiagnosticCollection, |
|
0 commit comments