Skip to content

Commit

Permalink
Updated to monaco-vscode-api 1.80.2. Clean-up monaco-language-client
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisalmen committed Aug 4, 2023
1 parent 95e0b69 commit 8282fa0
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 168 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ The following table describes which version of **monaco-languageclient** and **m

| monaco-languageclient | monaco-vscode-api | monaco-editor | comment |
| :---- | :---- | :--- | :--- |
| 6.3.0 | 1.80.2 | 0.40.0 | Released 2023-08-0x |
| 6.2.0 | 1.79.3 | 0.39.0 | Released 2023-06-16 |
| 6.1.0 | 1.79.1 | 0.38.0 | Released 2023-06-12 |
| 6.0.3 | 1.78.8 | 0.37.1 | Released 2023-05-31 |
Expand Down Expand Up @@ -250,7 +251,7 @@ loader.config({ monaco });
If you use pnpm, you have to add `vscode` / `monaco-vscode-api` as direct dependency (see the [following table](#monaco-editor--monaco-vscode-api-compatibility-table)), otherwise the installation will fail.

```json
"vscode": "npm:@codingame/monaco-vscode-api@~1.80.0"
"vscode": "npm:@codingame/monaco-vscode-api@~1.80.2"
```

## Licenses
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this npm module are documented in this file.

## [6.3.0] - 2023-08-0x

- Update to `monaco-editor` `0.40.0` and `monaco-vscode-api` `1.80.2` [#513](https://github.com/TypeFox/monaco-languageclient/pull/513)

## [6.2.0] - 2023-06-16

- Updated `monaco-vscode-api` to version `1.79.3`, `monaco-editor` to version `0.39.0` and `monaco-editor-workers` to version `0.39.1` [#503](https://github.com/TypeFox/monaco-languageclient/pull/503)
Expand Down
1 change: 0 additions & 1 deletion packages/client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ See [here](https://github.com/TypeFox/monaco-languageclient/blob/main/README.md)

## History


For the history please see the [README](https://github.com/TypeFox/monaco-languageclient/blob/main/README.md#latest-important-project-changes) and [CHANGELOG](https://github.com/TypeFox/monaco-languageclient/blob/main/CHANGELOG.md).

## License
Expand Down
4 changes: 2 additions & 2 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@
],
"dependencies": {
"monaco-editor": "~0.40.0",
"vscode": "npm:@codingame/monaco-vscode-api@1.80.1-next.0",
"vscode": "npm:@codingame/monaco-vscode-api@1.80.2",
"vscode-jsonrpc": "~8.1.0",
"vscode-languageclient": "~8.1.0"
},
"peerDependencies": {
"monaco-editor": "~0.40.0",
"vscode": "npm:@codingame/monaco-vscode-api@1.80.1-next.0"
"vscode": "npm:@codingame/monaco-vscode-api@1.80.2"
},
"peerDependenciesMeta": {
"monaco-editor": {
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */

export type { IConnectionProvider, MonacoLanguageClientOptions } from './monaco-language-client.js';
export * from './monaco-language-client.js';
export * from './monaco-vscode-api-services.js';
141 changes: 9 additions & 132 deletions packages/client/src/monaco-language-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,155 +3,32 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */

/* eslint-disable @typescript-eslint/dot-notation */

import { BaseLanguageClient, MessageTransports, LanguageClientOptions } from 'vscode-languageclient/lib/common/client.js';
import { ConfigurationFeature, SyncConfigurationFeature } from 'vscode-languageclient/lib/common/configuration.js';
import { DidChangeTextDocumentFeature, DidCloseTextDocumentFeature, DidOpenTextDocumentFeature, DidSaveTextDocumentFeature, WillSaveFeature, WillSaveWaitUntilFeature } from 'vscode-languageclient/lib/common/textSynchronization.js';
import { CompletionItemFeature } from 'vscode-languageclient/lib/common/completion.js';
import { HoverFeature } from 'vscode-languageclient/lib/common/hover.js';
import { SignatureHelpFeature } from 'vscode-languageclient/lib/common/signatureHelp.js';
import { DefinitionFeature } from 'vscode-languageclient/lib/common/definition.js';
import { ReferencesFeature } from 'vscode-languageclient/lib/common/reference.js';
import { DocumentHighlightFeature } from 'vscode-languageclient/lib/common/documentHighlight.js';
import { DocumentSymbolFeature } from 'vscode-languageclient/lib/common/documentSymbol.js';
import { CodeActionFeature } from 'vscode-languageclient/lib/common/codeAction.js';
import { CodeLensFeature } from 'vscode-languageclient/lib/common/codeLens.js';
import { DocumentFormattingFeature, DocumentOnTypeFormattingFeature, DocumentRangeFormattingFeature } from 'vscode-languageclient/lib/common/formatting.js';
import { RenameFeature } from 'vscode-languageclient/lib/common/rename.js';
import { DocumentLinkFeature } from 'vscode-languageclient/lib/common/documentLink.js';
import { ExecuteCommandFeature } from 'vscode-languageclient/lib/common/executeCommand.js';
import { TypeDefinitionFeature } from 'vscode-languageclient/lib/common/typeDefinition.js';
import { ImplementationFeature } from 'vscode-languageclient/lib/common/implementation.js';
import { ColorProviderFeature } from 'vscode-languageclient/lib/common/colorProvider.js';
import { WorkspaceFoldersFeature } from 'vscode-languageclient/lib/common/workspaceFolder.js';
import { FoldingRangeFeature } from 'vscode-languageclient/lib/common/foldingRange.js';
import { DeclarationFeature } from 'vscode-languageclient/lib/common/declaration.js';
import { SelectionRangeFeature } from 'vscode-languageclient/lib/common/selectionRange.js';
import { SemanticTokensFeature } from 'vscode-languageclient/lib/common/semanticTokens.js';
import { LinkedEditingFeature } from 'vscode-languageclient/lib/common/linkedEditingRange.js';
import { InlayHintsFeature } from 'vscode-languageclient/lib/common/inlayHint.js';
import { DiagnosticFeature } from 'vscode-languageclient/lib/common/diagnostic.js';
import { ProgressFeature } from 'vscode-languageclient/lib/common/progress.js';
import { RegistrationParams, UnregistrationParams } from 'vscode-languageclient';
import { TextDocument } from 'vscode';
import { WorkspaceSymbolFeature } from 'vscode-languageclient/lib/common/workspaceSymbol.js';
import { CallHierarchyFeature } from 'vscode-languageclient/lib/common/callHierarchy.js';
import { DidCreateFilesFeature, DidDeleteFilesFeature, DidRenameFilesFeature, WillCreateFilesFeature, WillDeleteFilesFeature, WillRenameFilesFeature } from 'vscode-languageclient/lib/common/fileOperations.js';
import { TypeHierarchyFeature } from 'vscode-languageclient/lib/common/typeHierarchy.js';
import { InlineValueFeature } from 'vscode-languageclient/lib/common/inlineValue.js';
import { NotebookDocumentSyncFeature } from 'vscode-languageclient/lib/common/notebook.js';

export interface IConnectionProvider {
get(encoding: string): Promise<MessageTransports>;
}

export type MonacoLanguageClientOptions = {
name: string;
id?: string;
clientOptions: LanguageClientOptions;
connectionProvider: IConnectionProvider;
}

export class MonacoLanguageClient extends BaseLanguageClient {
protected readonly connectionProvider: IConnectionProvider;

constructor({ id, name, clientOptions, connectionProvider }: MonacoLanguageClient.Options) {
constructor({ id, name, clientOptions, connectionProvider }: MonacoLanguageClientOptions) {
super(id || name.toLowerCase(), name, clientOptions);
this.connectionProvider = connectionProvider;

// Hack because vscode-language client rejects the whole registration block if one capability registration has no associated client feature registered
// Some language servers still send the registration even though the client says it doesn't support it
const originalHandleRegistrationRequest: (params: RegistrationParams) => Promise<void> = this['handleRegistrationRequest'].bind(this);
this['handleRegistrationRequest'] = (params: RegistrationParams) => {
originalHandleRegistrationRequest({
...params,
registrations: params.registrations.filter(registration => this.getFeature(<any>registration.method) != null)
});
};
const originalHandleUnregistrationRequest: (params: UnregistrationParams) => Promise<void> = this['handleUnregistrationRequest'].bind(this);
this['handleUnregistrationRequest'] = (params: UnregistrationParams) => {
originalHandleUnregistrationRequest({
...params,
unregisterations: params.unregisterations.filter(unregistration => this.getFeature(<any>unregistration.method) != null)
});
};
}

protected createMessageTransports(encoding: string): Promise<MessageTransports> {
return this.connectionProvider.get(encoding);
}

protected override getLocale(): string {
return navigator.language || 'en-US';
}

protected override registerBuiltinFeatures() {
const pendingFullTextDocumentChanges: Map<string, TextDocument> = new Map();
this.registerFeature(new ConfigurationFeature(this));
this.registerFeature(new DidOpenTextDocumentFeature(this, this['_syncedDocuments']));
this['_didChangeTextDocumentFeature'] = new DidChangeTextDocumentFeature(this, pendingFullTextDocumentChanges);
this['_didChangeTextDocumentFeature'].onPendingChangeAdded(() => {
this['triggerPendingChangeDelivery']();
});
this.registerFeature(this['_didChangeTextDocumentFeature']);
this.registerFeature(new DidCloseTextDocumentFeature(this, this['_syncedDocuments'], pendingFullTextDocumentChanges));
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 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 SemanticTokensFeature(this));
this.registerFeature(new LinkedEditingFeature(this));
this.registerFeature(new InlayHintsFeature(this));
this.registerFeature(new DiagnosticFeature(this));
// enabled since monaco-vscode-api 1.78.5 (PR https://github.com/CodinGame/monaco-vscode-api/pull/109)
this.registerFeature(new WillSaveFeature(this));
this.registerFeature(new WillSaveWaitUntilFeature(this));
this.registerFeature(new DidSaveTextDocumentFeature(this));
// enabled since monaco-vscode-api 1.79.0 (PR https://github.com/CodinGame/monaco-vscode-api/pull/110)
this.registerFeature(new WorkspaceSymbolFeature(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 CallHierarchyFeature(this));
this.registerFeature(new TypeHierarchyFeature(this));
this.registerFeature(new InlineValueFeature(this));
}

/**
* These are all contained in BaseLanguageClient#registerBuiltinFeatures but not registered
* in MonacoLanguageClient. This method is not called!
*/
public registerNotUsedFeatures() {
// these will stay unsupported for now
this.registerFeature(new ProgressFeature(this));
this.registerFeature(new NotebookDocumentSyncFeature(this));
}
}
export namespace MonacoLanguageClient {
export interface Options {
name: string;
id?: string;
clientOptions: LanguageClientOptions;
connectionProvider: IConnectionProvider;
return super.getLocale() || 'en-US';
}
}
28 changes: 7 additions & 21 deletions packages/client/src/monaco-vscode-api-services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ interface MonacoEnvironmentEnhanced extends Environment {
}

export type InitializeServiceConfig = {
enableFilesService?: boolean;
enableExtensionsService?: boolean;
enableDialogService?: boolean;
enableNotificationService?: boolean;
enableModelService?: boolean;
Expand Down Expand Up @@ -43,8 +41,6 @@ export type InitializeServiceConfig = {
enableSearchService?: boolean;
enableMarkersService?: boolean;
enableAccessibilityService?: boolean;
enableEnvironmentService?: boolean;
enableLayoutService?: boolean;
enableLanguageDetectionWorkerService?: boolean;
userServices?: editor.IEditorOverrideServices;
debugLogging?: boolean;
Expand Down Expand Up @@ -75,11 +71,14 @@ export const initServices = async (config?: InitializeServiceConfig) => {
(window.MonacoEnvironment as MonacoEnvironmentEnhanced).vscodeApiInitialised = true;
};

type ModuleWithDefaultExport = {
export type ModuleWithDefaultExport = {
default: (x?: any) => editor.IEditorOverrideServices
}

const importAllServices = async (config?: InitializeServiceConfig) => {
/**
* files, extension, environment and layout services are loaded automatically by monaco-vscode-api
*/
export const importAllServices = async (config?: InitializeServiceConfig) => {
const serviceNames: string[] = [];
const promises: Promise<ModuleWithDefaultExport>[] = [];
const lc: InitializeServiceConfig = config ?? {};
Expand All @@ -90,12 +89,6 @@ const importAllServices = async (config?: InitializeServiceConfig) => {
promises.push(promise);
};

if (lc.enableFilesService === true) {
addService('files', import('vscode/service-override/files'));
}
if (lc.enableExtensionsService === true) {
addService('extensions', import('vscode/service-override/extensions'));
}
if (lc.enableModelService === true) {
addService('model', import('vscode/service-override/model'));
}
Expand Down Expand Up @@ -157,12 +150,6 @@ const importAllServices = async (config?: InitializeServiceConfig) => {
if (lc.enableAccessibilityService === true) {
addService('accessibility', import('vscode/service-override/accessibility'));
}
if (lc.enableEnvironmentService === true) {
addService('environment', import('vscode/service-override/environment'));
}
if (lc.enableLayoutService === true) {
addService('layout', import('vscode/service-override/layout'));
}
if (lc.enableLanguageDetectionWorkerService === true) {
addService('languageDetectionWorker', import('vscode/service-override/languageDetectionWorker'));
}
Expand Down Expand Up @@ -193,8 +180,6 @@ const importAllServices = async (config?: InitializeServiceConfig) => {
reportServiceLoading(userServices, lc.debugLogging === true, 'user');
}

// files service and extension service are loaded automatically by monaco-vscode-api

// theme requires textmate
if ((serviceNames.includes('theme') || Object.keys(overrideServices).includes('themeService')) &&
!(serviceNames.includes('textmate') || Object.keys(overrideServices).includes('textMateTokenizationFeature'))) {
Expand Down Expand Up @@ -240,14 +225,15 @@ const importAllServices = async (config?: InitializeServiceConfig) => {
services = loadedImport.default(lc.configureTerminalServiceConfig.backendImpl);
}
} else if (serviceName === 'quickaccess') {
if (lc.configureEditorOrViewsServiceConfig?.enableViewsService) {
if (lc.configureEditorOrViewsServiceConfig?.enableViewsService === true) {
const {
isEditorPartVisible
} = await import('vscode/service-override/views');
services = loadedImport.default({
isKeybindingConfigurationVisible: isEditorPartVisible,
shouldUseGlobalPicker: isEditorPartVisible
});
services = loadedImport.default();
} else {
services = loadedImport.default();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/main/src/langium/langiumClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ const run = async () => {

try {
await initServices({
enableFilesService: true,
enableThemeService: true,
enableTextmateService: true,
enableModelService: true,
Expand All @@ -129,6 +128,7 @@ try {
},
enableKeybindingsService: true,
enableLanguagesService: true,
enableQuickaccessService: true,
debugLogging: true
});
await setup();
Expand Down
4 changes: 0 additions & 4 deletions packages/examples/main/src/langium/statemachineClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,6 @@ try {
enableQuickaccessService: true,
enableOutputService: true,
enableSearchService: true,
enableMarkersService: false,
// don't enable files and extensions services. They will be enabled automatically
enableFilesService: false,
enableExtensionsService: false,
enableLanguageDetectionWorkerService: true,
// This should demonstrate that you can chose to not use the built-in loading mechanism,
// but do it manually, see below
Expand Down
2 changes: 1 addition & 1 deletion packages/verify/pnpm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": {
"monaco-languageclient": "6.3.0-next.1",
"monaco-editor": "~0.40.0",
"vscode": "npm:@codingame/monaco-vscode-api@~1.80.1-next.0"
"vscode": "npm:@codingame/monaco-vscode-api@~1.80.2"
},
"devDependencies": {
"shx": "~0.3.4"
Expand Down

0 comments on commit 8282fa0

Please sign in to comment.