Skip to content

Commit

Permalink
feat: implemented provideDocumentHighlights
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Jun 9, 2022
1 parent 1cda6c6 commit f782496
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/monaco/code2monaco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,23 @@ export function asSymbolKind(kind: vscode.SymbolKind): monaco.languages.SymbolKi
return monaco.languages.SymbolKind.File;
}
}

export function asDocumentHighlight(highlight: vscode.DocumentHighlight): monaco.languages.DocumentHighlight {
return {
range: asRange(highlight.range),
kind: asDocumentHighlightKind(highlight.kind),
};
}

export function asDocumentHighlightKind(kind: vscode.DocumentHighlightKind | undefined): monaco.languages.DocumentHighlightKind {
switch (kind) {
case vscode.DocumentHighlightKind.Text:
return monaco.languages.DocumentHighlightKind.Text;
case vscode.DocumentHighlightKind.Read:
return monaco.languages.DocumentHighlightKind.Read;
case vscode.DocumentHighlightKind.Write:
return monaco.languages.DocumentHighlightKind.Write;
default:
return monaco.languages.DocumentHighlightKind.Text;
}
}
11 changes: 11 additions & 0 deletions src/monaco/ls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,17 @@ export async function setupLs(modelsMap: Ref<Map<string, monaco.editor.ITextMode
}
},
}),
monaco.languages.registerDocumentHighlightProvider(lang, {
provideDocumentHighlights: async (model, position) => {
const codeResult = await ls.findDocumentHighlights(
model.uri.toString(),
monaco2code.asPosition(position),
);
if (codeResult) {
return codeResult.map(code2monaco.asDocumentHighlight);
}
},
}),
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 f782496

Please sign in to comment.