-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as vscode from 'vscode'; | ||
import * as y3 from 'y3-helper'; | ||
|
||
export class CompletionProvider implements vscode.CompletionItemProvider { | ||
private async provideByKey(text: string, token: vscode.CancellationToken): Promise<vscode.CompletionItem[] | null> { | ||
let key = Number(text); | ||
if (!Number.isInteger(key)) { | ||
return null; | ||
} | ||
let objects = await y3.table.getAllObjects(); | ||
if (token.isCancellationRequested) { | ||
throw new vscode.CancellationError(); | ||
} | ||
let results: vscode.CompletionItem[] = []; | ||
|
||
for (const object of objects) { | ||
if (object.key.toString().startsWith(text)) { | ||
let item = new vscode.CompletionItem(object.key.toString(), vscode.CompletionItemKind.Unit); | ||
item.documentation = `${object.name}(${object.tableName})`; | ||
results.push(item); | ||
} | ||
} | ||
|
||
return results; | ||
} | ||
|
||
async provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext): Promise<vscode.CompletionItem[] | null> { | ||
if (context.triggerCharacter === '?') { | ||
return await this.provideByKey('', token); | ||
} else { | ||
let range = document.getWordRangeAtPosition(position); | ||
let text = document.getText(range); | ||
return await this.provideByKey(text, token); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as vscode from 'vscode'; | ||
import * as y3 from 'y3-helper'; | ||
|
||
export class DefinitionProvider implements vscode.DefinitionProvider { | ||
async provideDefinition(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Promise<vscode.DefinitionLink[] | null> { | ||
let range = document.getWordRangeAtPosition(position); | ||
let text = document.getText(range); | ||
let key = Number(text); | ||
if (!Number.isInteger(key)) { | ||
return null; | ||
} | ||
let objects = await y3.table.getObjectsByKey(key); | ||
if (token.isCancellationRequested) { | ||
throw new vscode.CancellationError(); | ||
} | ||
if (objects.length === 0) { | ||
return null; | ||
} | ||
let results: vscode.DefinitionLink[] = []; | ||
|
||
for (const object of objects) { | ||
if (!object.uri) { | ||
continue; | ||
} | ||
results.push({ | ||
targetUri: object.uri, | ||
targetRange: new vscode.Range(new vscode.Position(0, 0), new vscode.Position(0, 0)), | ||
}); | ||
} | ||
|
||
return results; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters