From a167e3d2bcc9d4a54e44fcafe2907b8235dcd731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Fri, 27 May 2022 10:41:37 +0200 Subject: [PATCH 1/3] refactor: Duplicate registerBuiltinFeatures method from base language client --- packages/client/src/monaco-language-client.ts | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/packages/client/src/monaco-language-client.ts b/packages/client/src/monaco-language-client.ts index 5f180133..54feabc1 100644 --- a/packages/client/src/monaco-language-client.ts +++ b/packages/client/src/monaco-language-client.ts @@ -12,6 +12,40 @@ import { IConnectionProvider } from './connection'; export * from 'vscode-languageclient/lib/common/client'; import type * as vscode from 'vscode' import { MonacoC2PConverter, MonacoP2CConverter } from "./converters"; +import { ConfigurationFeature, SyncConfigurationFeature } from "vscode-languageclient/lib/common/configuration"; +import { DidChangeTextDocumentFeature, DidCloseTextDocumentFeature, DidOpenTextDocumentFeature, DidSaveTextDocumentFeature, WillSaveFeature, WillSaveWaitUntilFeature } from "vscode-languageclient/lib/common/textSynchronization"; +import { CompletionItemFeature } from "vscode-languageclient/lib/common/completion"; +import { HoverFeature } from "vscode-languageclient/lib/common/hover"; +import { SignatureHelpFeature } from "vscode-languageclient/lib/common/signatureHelp"; +import { DefinitionFeature } from "vscode-languageclient/lib/common/definition"; +import { ReferencesFeature } from "vscode-languageclient/lib/common/reference"; +import { DocumentHighlightFeature } from "vscode-languageclient/lib/common/documentHighlight"; +import { DocumentSymbolFeature } from "vscode-languageclient/lib/common/documentSymbol"; +import { WorkspaceSymbolFeature } from "vscode-languageclient/lib/common/workspaceSymbol"; +import { CodeActionFeature } from "vscode-languageclient/lib/common/codeAction"; +import { CodeLensFeature } from "vscode-languageclient/lib/common/codeLens"; +import { DocumentFormattingFeature, DocumentOnTypeFormattingFeature, DocumentRangeFormattingFeature } from "vscode-languageclient/lib/common/formatting"; +import { RenameFeature } from "vscode-languageclient/lib/common/rename"; +import { DocumentLinkFeature } from "vscode-languageclient/lib/common/documentLink"; +import { ExecuteCommandFeature } from "vscode-languageclient/lib/common/executeCommand"; +import { TypeDefinitionFeature } from "vscode-languageclient/lib/common/typeDefinition"; +import { ImplementationFeature } from "vscode-languageclient/lib/common/implementation"; +import { ColorProviderFeature } from "vscode-languageclient/lib/common/colorProvider"; +import { WorkspaceFoldersFeature } from "vscode-languageclient/lib/common/workspaceFolder"; +import { FoldingRangeFeature } from "vscode-languageclient/lib/common/foldingRange"; +import { DeclarationFeature } from "vscode-languageclient/lib/common/declaration"; +import { SelectionRangeFeature } from "vscode-languageclient/lib/common/selectionRange"; +import { SemanticTokensFeature } from "vscode-languageclient/lib/common/semanticTokens"; +import { LinkedEditingFeature } from "vscode-languageclient/lib/common/linkedEditingRange"; +import { TypeHierarchyFeature } from "vscode-languageclient/lib/common/typeHierarchy"; +import { InlayHintsFeature } from "vscode-languageclient/lib/common/inlayHint"; +import { DiagnosticFeature } from "vscode-languageclient/lib/common/diagnostic"; +import { ProgressFeature } from "vscode-languageclient/lib/common/progress"; +import { CallHierarchyFeature } from "vscode-languageclient/lib/common/callHierarchy"; +import { DidCreateFilesFeature, DidDeleteFilesFeature, DidRenameFilesFeature, WillCreateFilesFeature, WillDeleteFilesFeature, WillRenameFilesFeature } from "vscode-languageclient/lib/common/fileOperations"; +import { InlineValueFeature } from "vscode-languageclient/lib/common/inlineValue"; +import { NotebookDocumentSyncFeature } from "vscode-languageclient/lib/common/notebook"; +import { FileSystemWatcherFeature } from 'vscode-languageclient/lib/common/fileSystemWatcher'; export class MonacoLanguageClient extends BaseLanguageClient { @@ -39,6 +73,60 @@ export class MonacoLanguageClient extends BaseLanguageClient { protected getLocale(): string { return navigator.language || 'en-US' } + + protected override registerBuiltinFeatures() { + this.registerFeature(new ConfigurationFeature(this)); + this.registerFeature(new DidOpenTextDocumentFeature(this, this['_syncedDocuments'])); + this.registerFeature(new DidChangeTextDocumentFeature(this)); + this.registerFeature(new WillSaveFeature(this)); + this.registerFeature(new WillSaveWaitUntilFeature(this)); + this.registerFeature(new DidSaveTextDocumentFeature(this)); + this.registerFeature(new DidCloseTextDocumentFeature(this, this['_syncedDocuments'])); + this.registerFeature(new FileSystemWatcherFeature(this, (event) => this['notifyFileEvent'](event))); + this.registerFeature(new CompletionItemFeature(this)); + this.registerFeature(new HoverFeature(this)); + this.registerFeature(new SignatureHelpFeature(this)); + this.registerFeature(new DefinitionFeature(this)); + this.registerFeature(new ReferencesFeature(this)); + this.registerFeature(new DocumentHighlightFeature(this)); + this.registerFeature(new DocumentSymbolFeature(this)); + this.registerFeature(new WorkspaceSymbolFeature(this)); + this.registerFeature(new CodeActionFeature(this)); + this.registerFeature(new CodeLensFeature(this)); + this.registerFeature(new DocumentFormattingFeature(this)); + this.registerFeature(new DocumentRangeFormattingFeature(this)); + this.registerFeature(new DocumentOnTypeFormattingFeature(this)); + this.registerFeature(new RenameFeature(this)); + this.registerFeature(new DocumentLinkFeature(this)); + this.registerFeature(new ExecuteCommandFeature(this)); + this.registerFeature(new SyncConfigurationFeature(this)); + this.registerFeature(new TypeDefinitionFeature(this)); + this.registerFeature(new ImplementationFeature(this)); + this.registerFeature(new ColorProviderFeature(this)); + // We only register the workspace folder feature if the client is not locked + // to a specific workspace folder. + if (this.clientOptions.workspaceFolder === undefined) { + this.registerFeature(new WorkspaceFoldersFeature(this)); + } + this.registerFeature(new FoldingRangeFeature(this)); + this.registerFeature(new DeclarationFeature(this)); + this.registerFeature(new SelectionRangeFeature(this)); + this.registerFeature(new ProgressFeature(this)); + this.registerFeature(new CallHierarchyFeature(this)); + this.registerFeature(new SemanticTokensFeature(this)); + this.registerFeature(new LinkedEditingFeature(this)); + this.registerFeature(new DidCreateFilesFeature(this)); + this.registerFeature(new DidRenameFilesFeature(this)); + this.registerFeature(new DidDeleteFilesFeature(this)); + this.registerFeature(new WillCreateFilesFeature(this)); + this.registerFeature(new WillRenameFilesFeature(this)); + this.registerFeature(new WillDeleteFilesFeature(this)); + this.registerFeature(new TypeHierarchyFeature(this)); + this.registerFeature(new InlineValueFeature(this)); + this.registerFeature(new InlayHintsFeature(this)); + this.registerFeature(new DiagnosticFeature(this)); + this.registerFeature(new NotebookDocumentSyncFeature(this)); + } } export namespace MonacoLanguageClient { export interface Options { From cb970a8adacbf0d7ca704f7e62261ba280bbbf73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Fri, 27 May 2022 10:46:22 +0200 Subject: [PATCH 2/3] Remove unsupported features --- packages/client/src/monaco-language-client.ts | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/packages/client/src/monaco-language-client.ts b/packages/client/src/monaco-language-client.ts index 54feabc1..7b9013dd 100644 --- a/packages/client/src/monaco-language-client.ts +++ b/packages/client/src/monaco-language-client.ts @@ -21,7 +21,6 @@ import { DefinitionFeature } from "vscode-languageclient/lib/common/definition"; import { ReferencesFeature } from "vscode-languageclient/lib/common/reference"; import { DocumentHighlightFeature } from "vscode-languageclient/lib/common/documentHighlight"; import { DocumentSymbolFeature } from "vscode-languageclient/lib/common/documentSymbol"; -import { WorkspaceSymbolFeature } from "vscode-languageclient/lib/common/workspaceSymbol"; import { CodeActionFeature } from "vscode-languageclient/lib/common/codeAction"; import { CodeLensFeature } from "vscode-languageclient/lib/common/codeLens"; import { DocumentFormattingFeature, DocumentOnTypeFormattingFeature, DocumentRangeFormattingFeature } from "vscode-languageclient/lib/common/formatting"; @@ -37,15 +36,9 @@ import { DeclarationFeature } from "vscode-languageclient/lib/common/declaration import { SelectionRangeFeature } from "vscode-languageclient/lib/common/selectionRange"; import { SemanticTokensFeature } from "vscode-languageclient/lib/common/semanticTokens"; import { LinkedEditingFeature } from "vscode-languageclient/lib/common/linkedEditingRange"; -import { TypeHierarchyFeature } from "vscode-languageclient/lib/common/typeHierarchy"; import { InlayHintsFeature } from "vscode-languageclient/lib/common/inlayHint"; import { DiagnosticFeature } from "vscode-languageclient/lib/common/diagnostic"; import { ProgressFeature } from "vscode-languageclient/lib/common/progress"; -import { CallHierarchyFeature } from "vscode-languageclient/lib/common/callHierarchy"; -import { DidCreateFilesFeature, DidDeleteFilesFeature, DidRenameFilesFeature, WillCreateFilesFeature, WillDeleteFilesFeature, WillRenameFilesFeature } from "vscode-languageclient/lib/common/fileOperations"; -import { InlineValueFeature } from "vscode-languageclient/lib/common/inlineValue"; -import { NotebookDocumentSyncFeature } from "vscode-languageclient/lib/common/notebook"; -import { FileSystemWatcherFeature } from 'vscode-languageclient/lib/common/fileSystemWatcher'; export class MonacoLanguageClient extends BaseLanguageClient { @@ -82,7 +75,6 @@ export class MonacoLanguageClient extends BaseLanguageClient { this.registerFeature(new WillSaveWaitUntilFeature(this)); this.registerFeature(new DidSaveTextDocumentFeature(this)); this.registerFeature(new DidCloseTextDocumentFeature(this, this['_syncedDocuments'])); - this.registerFeature(new FileSystemWatcherFeature(this, (event) => this['notifyFileEvent'](event))); this.registerFeature(new CompletionItemFeature(this)); this.registerFeature(new HoverFeature(this)); this.registerFeature(new SignatureHelpFeature(this)); @@ -90,7 +82,6 @@ export class MonacoLanguageClient extends BaseLanguageClient { this.registerFeature(new ReferencesFeature(this)); this.registerFeature(new DocumentHighlightFeature(this)); this.registerFeature(new DocumentSymbolFeature(this)); - this.registerFeature(new WorkspaceSymbolFeature(this)); this.registerFeature(new CodeActionFeature(this)); this.registerFeature(new CodeLensFeature(this)); this.registerFeature(new DocumentFormattingFeature(this)); @@ -112,20 +103,10 @@ export class MonacoLanguageClient extends BaseLanguageClient { this.registerFeature(new DeclarationFeature(this)); this.registerFeature(new SelectionRangeFeature(this)); this.registerFeature(new ProgressFeature(this)); - this.registerFeature(new CallHierarchyFeature(this)); this.registerFeature(new SemanticTokensFeature(this)); this.registerFeature(new LinkedEditingFeature(this)); - this.registerFeature(new DidCreateFilesFeature(this)); - this.registerFeature(new DidRenameFilesFeature(this)); - this.registerFeature(new DidDeleteFilesFeature(this)); - this.registerFeature(new WillCreateFilesFeature(this)); - this.registerFeature(new WillRenameFilesFeature(this)); - this.registerFeature(new WillDeleteFilesFeature(this)); - this.registerFeature(new TypeHierarchyFeature(this)); - this.registerFeature(new InlineValueFeature(this)); this.registerFeature(new InlayHintsFeature(this)); this.registerFeature(new DiagnosticFeature(this)); - this.registerFeature(new NotebookDocumentSyncFeature(this)); } } export namespace MonacoLanguageClient { From 0d52019e49d579aa3c9e0645001c2ee8ac00654f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Fri, 27 May 2022 10:55:00 +0200 Subject: [PATCH 3/3] Move optional features in dedicated methods --- packages/client/src/monaco-language-client.ts | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/client/src/monaco-language-client.ts b/packages/client/src/monaco-language-client.ts index 7b9013dd..2fce6dbf 100644 --- a/packages/client/src/monaco-language-client.ts +++ b/packages/client/src/monaco-language-client.ts @@ -68,12 +68,8 @@ export class MonacoLanguageClient extends BaseLanguageClient { } protected override registerBuiltinFeatures() { - this.registerFeature(new ConfigurationFeature(this)); this.registerFeature(new DidOpenTextDocumentFeature(this, this['_syncedDocuments'])); this.registerFeature(new DidChangeTextDocumentFeature(this)); - this.registerFeature(new WillSaveFeature(this)); - this.registerFeature(new WillSaveWaitUntilFeature(this)); - this.registerFeature(new DidSaveTextDocumentFeature(this)); this.registerFeature(new DidCloseTextDocumentFeature(this, this['_syncedDocuments'])); this.registerFeature(new CompletionItemFeature(this)); this.registerFeature(new HoverFeature(this)); @@ -90,7 +86,6 @@ export class MonacoLanguageClient extends BaseLanguageClient { this.registerFeature(new RenameFeature(this)); this.registerFeature(new DocumentLinkFeature(this)); this.registerFeature(new ExecuteCommandFeature(this)); - this.registerFeature(new SyncConfigurationFeature(this)); this.registerFeature(new TypeDefinitionFeature(this)); this.registerFeature(new ImplementationFeature(this)); this.registerFeature(new ColorProviderFeature(this)); @@ -102,12 +97,26 @@ export class MonacoLanguageClient extends BaseLanguageClient { this.registerFeature(new FoldingRangeFeature(this)); this.registerFeature(new DeclarationFeature(this)); this.registerFeature(new SelectionRangeFeature(this)); - this.registerFeature(new ProgressFeature(this)); this.registerFeature(new SemanticTokensFeature(this)); this.registerFeature(new LinkedEditingFeature(this)); this.registerFeature(new InlayHintsFeature(this)); this.registerFeature(new DiagnosticFeature(this)); } + + public registerTextDocumentSaveFeatures() { + this.registerFeature(new WillSaveFeature(this)); + this.registerFeature(new WillSaveWaitUntilFeature(this)); + this.registerFeature(new DidSaveTextDocumentFeature(this)); + } + + public registerConfigurationFeatures() { + this.registerFeature(new ConfigurationFeature(this)); + this.registerFeature(new SyncConfigurationFeature(this)); + } + + public registerProgressFeatures() { + this.registerFeature(new ProgressFeature(this)); + } } export namespace MonacoLanguageClient { export interface Options {