jvikstrom created this revision. jvikstrom added reviewers: hokein, ilya-biryukov. Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay. Herald added a project: clang.
This adds a SemanticHighlighting feature to the vscode extension that does not do anything. It adds the notification handler to the clangd client and registers the feature as an experimental feature sending the relevant data to the clangd server. The notification handler does not currently do anything if/when clangd sends a semantic highlighting notification. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D65395 Files: clang-tools-extra/clangd/clients/clangd-vscode/.gitignore clang-tools-extra/clangd/clients/clangd-vscode/src/SemanticHighlighting.ts clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts
Index: clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts =================================================================== --- clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts +++ clang-tools-extra/clangd/clients/clangd-vscode/src/extension.ts @@ -1,5 +1,6 @@ import * as vscode from 'vscode'; import * as vscodelc from 'vscode-languageclient'; +import { SemanticHighlighting } from './SemanticHighlighting'; /** * Method to get workspace configuration option @@ -12,9 +13,9 @@ } namespace SwitchSourceHeaderRequest { -export const type = - new vscodelc.RequestType<vscodelc.TextDocumentIdentifier, string|undefined, - void, void>('textDocument/switchSourceHeader'); + export const type = + new vscodelc.RequestType<vscodelc.TextDocumentIdentifier, string | undefined, + void, void>('textDocument/switchSourceHeader'); } class FileStatus { @@ -32,8 +33,8 @@ const path = vscode.window.activeTextEditor.document.fileName; const status = this.statuses.get(path); if (!status) { - this.statusBarItem.hide(); - return; + this.statusBarItem.hide(); + return; } this.statusBarItem.text = `clangd: ` + status.state; this.statusBarItem.show(); @@ -73,25 +74,30 @@ // However, VSCode does not have CUDA as a supported language yet, so we // cannot add a corresponding activationEvent for CUDA files and clangd will // *not* load itself automatically on '.cu' files. - const cudaFilePattern: string = '**/*.{' +['cu'].join()+ '}'; + const cudaFilePattern: string = '**/*.{' + ['cu'].join() + '}'; const clientOptions: vscodelc.LanguageClientOptions = { // Register the server for c-family and cuda files. documentSelector: [ { scheme: 'file', language: 'c' }, { scheme: 'file', language: 'cpp' }, - { scheme: 'file', language: 'objective-c'}, - { scheme: 'file', language: 'objective-cpp'}, + { scheme: 'file', language: 'objective-c' }, + { scheme: 'file', language: 'objective-cpp' }, { scheme: 'file', pattern: cudaFilePattern }, ], synchronize: !syncFileEvents ? undefined : { - // FIXME: send sync file events when clangd provides implemenatations. + // FIXME: send sync file events when clangd provides implemenatations. }, initializationOptions: { clangdFileStatus: true }, // Do not switch to output window when clangd returns output revealOutputChannelOn: vscodelc.RevealOutputChannelOn.Never }; - const clangdClient = new vscodelc.LanguageClient('Clang Language Server',serverOptions, clientOptions); + const clangdClient = new vscodelc.LanguageClient('Clang Language Server', serverOptions, clientOptions); + const semanticHighlightingFeature = new SemanticHighlighting.Feature(); + clangdClient.registerFeature(semanticHighlightingFeature); + // The notification handler must be registered after the client is ready or the client will crash. + clangdClient.onReady().then(() => clangdClient.onNotification(SemanticHighlighting.NotificationType, semanticHighlightingFeature.handleNotification)); + console.log('Clang Language Server is now active!'); context.subscriptions.push(clangdClient.start()); context.subscriptions.push(vscode.commands.registerCommand( @@ -131,5 +137,5 @@ // An empty place holder for the activate command, otherwise we'll get an // "command is not registered" error. context.subscriptions.push(vscode.commands.registerCommand( - 'clangd-vscode.activate', async () => {})); + 'clangd-vscode.activate', async () => { })); } Index: clang-tools-extra/clangd/clients/clangd-vscode/src/SemanticHighlighting.ts =================================================================== --- /dev/null +++ clang-tools-extra/clangd/clients/clangd-vscode/src/SemanticHighlighting.ts @@ -0,0 +1,36 @@ +import * as vscodelc from 'vscode-languageclient'; +import { DocumentSelector } from 'vscode-languageclient'; + +export namespace SemanticHighlighting { + interface HighlightingLineInformation { + line: number, + tokens: string, + }; + interface HighlightingInformation { + textDocument: { + uri: String, + }, + lines: [HighlightingLineInformation], + } + + export const NotificationType = new vscodelc.NotificationType<{}, void>('textDocument/semanticHighlighting'); + + // The feature that should be registered in the vscode lsp for enabling experimental semantic highlighting. + export class Feature implements vscodelc.StaticFeature { + scopes: string[]; + fillClientCapabilities(capabilities: vscodelc.ClientCapabilities) { + // Must use an experimental capability as the other's are strongly typed. + if (!capabilities.experimental) + capabilities.experimental = {}; + capabilities.experimental.semanticHighlightingCapabilities = { semanticHighlighting: true }; + } + + initialize(capabilities: vscodelc.ServerCapabilities, documentSelector: DocumentSelector | undefined) { + // Get the scopes from an experimental capability for the same reason that it is registered as experimental. + if (capabilities.experimental && capabilities.experimental.semanticHighlighting) + this.scopes = capabilities.experimental.semanticHighlighting.scopes; + } + + handleNotification(params: HighlightingInformation) { } + } +}; Index: clang-tools-extra/clangd/clients/clangd-vscode/.gitignore =================================================================== --- clang-tools-extra/clangd/clients/clangd-vscode/.gitignore +++ clang-tools-extra/clangd/clients/clangd-vscode/.gitignore @@ -1,2 +1,3 @@ out node_modules +.vscode-test
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits