Skip to content

Commit

Permalink
feat: implemented provideReferences
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Jun 9, 2022
1 parent 86079ad commit 6b05d17
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/monaco/Monaco.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const editor = shallowRef<monaco.editor.IStandaloneCodeEditor | undefined>(undef
const currentModel = shallowRef<monaco.editor.ITextModel>(
getOrCreateModel(
monaco.Uri.parse('playground:///demo.vue'),
monaco.Uri.parse('file:///demo.vue'),
'vue',
props.value ?? ''
)
Expand Down
18 changes: 13 additions & 5 deletions src/monaco/code2monaco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,19 @@ export function asMarkdownString(markdownString: vscode.Hover['contents']): mona
}
}

export function asLocation(definition: vscode.LocationLink): monaco.languages.Location {
return {
uri: asUri(definition.targetUri),
range: asRange(definition.targetRange),
};
export function asLocation(definition: vscode.LocationLink | vscode.Location): monaco.languages.Location {
if ('targetUri' in definition) {
return {
uri: asUri(definition.targetUri),
range: asRange(definition.targetRange),
};
}
else {
return {
uri: asUri(definition.uri),
range: asRange(definition.range),
};
}
}

export function asUri(uri: vscode.URI): monaco.Uri {
Expand Down
15 changes: 15 additions & 0 deletions src/monaco/ls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,21 @@ export async function setupLs(modelsMap: Ref<Map<string, monaco.editor.ITextMode
const completionItems = new WeakMap<monaco.languages.CompletionItem, vscode.CompletionItem>();

disposables.value.push(
// TODO: registerTokensProviderFactory
// TODO: setTokensProvider
// TODO: setMonarchTokensProvider
monaco.languages.registerReferenceProvider(lang, {
provideReferences: async (model, position) => {
const codeResult = await ls.findReferences(
model.uri.toString(),
monaco2code.asPosition(position),
);
// TODO: can't show if only one result from libs
if (codeResult) {
return codeResult.map(code2monaco.asLocation);
}
},
}),
monaco.languages.registerCompletionItemProvider(lang, {
// https://github.com/johnsoncodehk/volar/blob/2f786182250d27e99cc3714fbfc7d209616e2289/packages/vue-language-server/src/registers/registerlanguageFeatures.ts#L57
triggerCharacters: '!@#$%^&*()_+-=`~{}|[]\:";\'<>?,./ '.split(''),
Expand Down

0 comments on commit 6b05d17

Please sign in to comment.