Skip to content

Commit

Permalink
Merge pull request #780 from TypeFox/lc-config
Browse files Browse the repository at this point in the history
Remove languageId configuration ambiguity
  • Loading branch information
kaisalmen authored Nov 8, 2024
2 parents 3b48e50 + 1f54a53 commit d4eb93a
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 28 deletions.
4 changes: 1 addition & 3 deletions packages/examples/src/clangd/client/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ export const createWrapperConfig = async (config: {
clangdWorkerHandler: ClangdWorkerHandler,
lsMessageLocalPort: MessagePort
}): Promise<WrapperConfig> => {
const languageId = 'cpp';
return {
logLevel: LogLevel.Debug,
languageClientConfigs: {
LANGUAGE_ID: {
languageId: languageId,
name: 'Clangd WASM Language Server',
connection: {
options: {
Expand All @@ -47,7 +45,7 @@ export const createWrapperConfig = async (config: {
keepWorker: true
},
clientOptions: {
documentSelector: [languageId],
documentSelector: ['cpp'],
workspaceFolder: {
index: 0,
name: 'workspace',
Expand Down
1 change: 0 additions & 1 deletion packages/examples/src/eclipse.jdt.ls/client/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export const runEclipseJdtLsClient = () => {
},
languageClientConfigs: {
java: {
languageId: 'java',
connection: {
options: {
$type: 'WebSocketUrl',
Expand Down
4 changes: 3 additions & 1 deletion packages/examples/src/groovy/client/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ const userConfig: WrapperConfig = {
},
languageClientConfigs: {
groovy: {
languageId: 'groovy',
clientOptions: {
documentSelector: ['groovy']
},
connection: {
options: {
$type: 'WebSocketUrl',
Expand Down
4 changes: 3 additions & 1 deletion packages/examples/src/json/client/wrapperWs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export const buildJsonClientUserConfig = (params: {
},
languageClientConfigs: {
json: {
languageId: 'json',
clientOptions: {
documentSelector: ['json']
},
connection: {
options: {
$type: 'WebSocketUrl',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export const setupLangiumClientClassic = async (): Promise<WrapperConfig> => {
},
languageClientConfigs: {
langium: {
languageId: 'langium',
clientOptions: {
documentSelector: ['langium']
},
connection: {
options: {
$type: 'WorkerDirect',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ export const setupLangiumClientExtended = async (): Promise<WrapperConfig> => {
},
languageClientConfigs: {
langium: {
languageId: 'langium',
clientOptions: {
documentSelector: ['langium']
},
connection: {
options: {
$type: 'WorkerDirect',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export const createLangiumGlobalConfig = async (params: {

const languageClientConfigs: Record<string, LanguageClientConfig> | undefined = params.useLanguageClient && params.worker ? {
statemachine: {
languageId: 'statemachine',
clientOptions: {
documentSelector: ['statemachine']
},
connection: {
options: {
$type: 'WorkerDirect',
Expand Down
5 changes: 3 additions & 2 deletions packages/examples/src/multi/twoLanguageClients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ print("Hello Moon!")
},
languageClientConfigs: {
json: {
languageId: 'json',
clientOptions: {
documentSelector: ['json']
},
name: 'JSON Client',
connection: {
options: {
Expand All @@ -72,7 +74,6 @@ print("Hello Moon!")
}
},
python: {
languageId: 'python',
name: 'Python Client',
connection: {
options: {
Expand Down
1 change: 0 additions & 1 deletion packages/examples/src/python/client/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const createUserConfig = (workspaceRoot: string, code: string, codeUri: s
return {
languageClientConfigs: {
python: {
languageId: 'python',
name: 'Python Language Server Example',
connection: {
options: {
Expand Down
18 changes: 7 additions & 11 deletions packages/wrapper/src/languageClientWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ export interface ConnectionConfig {

export interface LanguageClientConfig {
name?: string;
languageId: string;
connection: ConnectionConfig;
clientOptions?: LanguageClientOptions;
clientOptions: LanguageClientOptions;
restartOptions?: LanguageClientRestartOptions;
}

Expand All @@ -37,7 +36,6 @@ export class LanguageClientWrapper {

private languageClient?: MonacoLanguageClient;
private languageClientConfig: LanguageClientConfig;
private languageId: string;
private worker?: Worker;
private port?: MessagePort;
private name?: string;
Expand All @@ -50,7 +48,6 @@ export class LanguageClientWrapper {
this.languageClientConfig = config.languageClientConfig;
this.name = this.languageClientConfig.name ?? 'unnamed';
this.logger = config.logger;
this.languageId = this.languageClientConfig.languageId;
}

haveLanguageClient(): boolean {
Expand Down Expand Up @@ -175,21 +172,20 @@ export class LanguageClientWrapper {
this.logger?.info('performLanguageClientStart: monaco-languageclient already running!');
resolve();
}

const mlcConfig = {
name: this.languageClientConfig.name ?? 'Monaco Wrapper Language Client',

// allow to fully override the clientOptions
clientOptions: this.languageClientConfig.clientOptions ?? {
documentSelector: [this.languageId],
// disable the default error handler
clientOptions: {
// disable the default error handler...
errorHandler: {
error: () => ({ action: ErrorAction.Continue }),
closed: () => ({ action: CloseAction.DoNotRestart })
}
},
// ...but allowm to override all options
...this.languageClientConfig.clientOptions,
},
messageTransports
};

this.languageClient = new MonacoLanguageClient(mlcConfig);

const conOptions = this.languageClientConfig.connection.options;
Expand Down
20 changes: 15 additions & 5 deletions packages/wrapper/test/languageClientWrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ describe('Test LanguageClientWrapper', () => {
name: 'Langium LS',
});
const languageClientConfig: LanguageClientConfig = {
languageId: 'javascript',
clientOptions: {
documentSelector: ['javascript']
},
connection: {
options: {
$type: 'WorkerDirect',
Expand All @@ -51,7 +53,9 @@ describe('Test LanguageClientWrapper', () => {
const config = createWrapperConfigExtendedApp();
config.languageClientConfigs = {
javascript: {
languageId: 'javascript',
clientOptions: {
documentSelector: ['javascript']
},
connection: {
options: {
$type: 'WorkerDirect',
Expand Down Expand Up @@ -84,7 +88,9 @@ describe('Test LanguageClientWrapper', () => {
const config = createWrapperConfigExtendedApp();
config.languageClientConfigs = {
javascript: {
languageId: 'javascript',
clientOptions: {
documentSelector: ['javascript']
},
connection: {
options: {
$type: 'WebSocketUrl',
Expand All @@ -104,7 +110,9 @@ describe('Test LanguageClientWrapper', () => {
const config = createWrapperConfigExtendedApp();
config.languageClientConfigs = {
javascript: {
languageId: 'javascript',
clientOptions: {
documentSelector: ['javascript']
},
name: 'test-unreachable',
connection: {
options: {
Expand Down Expand Up @@ -141,7 +149,9 @@ describe('Test LanguageClientWrapper', () => {
const config = createWrapperConfigExtendedApp();
config.languageClientConfigs = {
javascript: {
languageId: 'javascript',
clientOptions: {
documentSelector: ['javascript']
},
connection: {
options: {
$type: 'WorkerConfig',
Expand Down

0 comments on commit d4eb93a

Please sign in to comment.