Skip to content

Commit

Permalink
Naming enhancements, config restructuring
Browse files Browse the repository at this point in the history
- UserConfig is now WrapperConfig and one level less deep
- Language client config has better names and is structured more logically
- Introduce new two_langauge_clients.html example replacing wrapper_adv.html
  • Loading branch information
kaisalmen committed Sep 5, 2024
1 parent 62b8561 commit 45c7fc3
Show file tree
Hide file tree
Showing 34 changed files with 520 additions and 527 deletions.
7 changes: 5 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ <h3>Groovy</h3>
<a href="./packages/examples/groovy.html">Groovy Language Client & Language Server (Web Socket)</a>
<br>

<h3>Multiple Languageclients</h3>
Please execute <b><code>npm run start:example:server:python</code></b> and <b><code>npm run start:example:server:json</code></b> beforehand:<br>
<a href="./packages/examples/two_langauge_clients.html">Json & Python Languageclients & Language Server (Web Socket)</a>
<br>

<h2>Monaco Editor React</h2>
<a href="./packages/examples/react_statemachine.html">React: Langium Statemachine Language Client & Language Server (Worker)</a>
<br>
Expand All @@ -65,8 +70,6 @@ <h2>Monaco Editor React</h2>
<h3>monaco-editor related examples</h3>
<a href="./packages/examples/wrapper_ts.html">Monaco Editor Wrapper TypeScript Example</a>
<br>
<a href="./packages/examples/wrapper_adv.html">Multiple Editors</a>
<br>

<h2>Verification</h2>
<h3>Angular</h2>
Expand Down
10 changes: 3 additions & 7 deletions packages/client/src/commonTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ export type LanguageClientRestartOptions = {
keepWorker?: boolean;
}

export type LanguageClientConfigType = 'WebSocket' | 'WebSocketUrl' | 'WebSocketDirect' | 'WorkerConfig' | 'Worker';

export type ConnetionConfigOptions = (WebSocketConfigOptionsDirect | WebSocketConfigOptionsParams | WebSocketConfigOptionsUrl | WorkerConfigOptions | WorkerConfigDirect) & {
restartOptions?: LanguageClientRestartOptions;
}
export type ConnetionConfigOptions = (WebSocketConfigOptionsDirect | WebSocketConfigOptionsParams | WebSocketConfigOptionsUrl | WorkerConfigOptionsParams | WorkerConfigOptionsDirect);

export type WebSocketUrlParams = {
secured: boolean;
Expand Down Expand Up @@ -55,15 +51,15 @@ export type WebSocketConfigOptionsUrl = WebSocketUrlString & {
stopOptions?: WebSocketCallOptions;
}

export type WorkerConfigOptions = {
export type WorkerConfigOptionsParams = {
$type: 'WorkerConfig'
url: URL;
type: 'classic' | 'module';
messagePort?: MessagePort;
workerName?: string;
};

export type WorkerConfigDirect = {
export type WorkerConfigOptionsDirect = {
$type: 'WorkerDirect';
worker: Worker;
messagePort?: MessagePort;
Expand Down
9 changes: 8 additions & 1 deletion packages/examples/build/downloadResources.mts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,12 @@ const downloadVsix = async (url: string, targetDir: string, filename: string) =>
}
};

// Source: https://gist.github.com/wanglf/7acc591890dc0d8ceff1e7ec9af32a55?permalink_comment_id=4151555#gistcomment-4151555
// https://marketplace.visualstudio.com/_apis/public/gallery/publishers/${publisher}/vsextensions/${extension}/${version}/vspackage

await downloadVsix('https://marketplace.visualstudio.com/_apis/public/gallery/publishers/GitHub/vsextensions/github-vscode-theme/6.3.4/vspackage',
resolve(getLocalDirectory(), '../resources/vsix/'), 'GitHub.github-vscode-theme-6.3.4.vsix');
resolve(getLocalDirectory(), '../resources/vsix/'), 'github-vscode-theme.vsix');

// not yet used
await downloadVsix('https://marketplace.visualstudio.com/_apis/public/gallery/publishers/TypeFox/vsextensions/open-collaboration-tools/0.2.3/vspackage',
resolve(getLocalDirectory(), '../resources/vsix/'), 'open-collaboration-tools.vsix');
44 changes: 21 additions & 23 deletions packages/examples/src/browser/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import '@codingame/monaco-vscode-json-default-extension';
import { getLanguageService, TextDocument } from 'vscode-json-languageservice';
import { createConverter as createCodeConverter } from 'vscode-languageclient/lib/common/codeConverter.js';
import { createConverter as createProtocolConverter } from 'vscode-languageclient/lib/common/protocolConverter.js';
import { MonacoEditorLanguageClientWrapper, UserConfig } from 'monaco-editor-wrapper';
import { MonacoEditorLanguageClientWrapper, WrapperConfig } from 'monaco-editor-wrapper';
import { useWorkerFactory } from 'monaco-editor-wrapper/workerFactory';

export const configureMonacoWorkers = () => {
Expand All @@ -36,30 +36,28 @@ export const runBrowserEditor = async () => {
const codeUri = '/workspace/model.json';

const wrapper = new MonacoEditorLanguageClientWrapper();
const jsonClientUserConfig: UserConfig = {
wrapperConfig: {
serviceConfig: {
userServices: {
...getKeybindingsServiceOverride(),
},
debugLogging: true
const jsonClientUserConfig: WrapperConfig = {
serviceConfig: {
userServices: {
...getKeybindingsServiceOverride(),
},
editorAppConfig: {
$type: 'extended',
codeResources: {
main: {
text: code,
uri: codeUri
}
},
useDiffEditor: false,
userConfiguration: {
json: JSON.stringify({
'workbench.colorTheme': 'Default Dark Modern',
'editor.guides.bracketPairsHorizontal': 'active',
'editor.lightbulb.enabled': 'On'
})
debugLogging: true
},
editorAppConfig: {
$type: 'extended',
codeResources: {
main: {
text: code,
uri: codeUri
}
},
useDiffEditor: false,
userConfiguration: {
json: JSON.stringify({
'workbench.colorTheme': 'Default Dark Modern',
'editor.guides.bracketPairsHorizontal': 'active',
'editor.lightbulb.enabled': 'On'
})
}
}
};
Expand Down
11 changes: 11 additions & 0 deletions packages/examples/src/common/client/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* --------------------------------------------------------------------------------------------
* Copyright (c) 2024 TypeFox and others.
* Licensed under the MIT License. See LICENSE in the package root for license information.
* ------------------------------------------------------------------------------------------ */

export const disableButton = (id: string, disabled: boolean) => {
const button = document.getElementById(id) as HTMLButtonElement | null;
if (button !== null) {
button.disabled = disabled;
}
};
49 changes: 24 additions & 25 deletions packages/examples/src/eclipse.jdt.ls/client/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as vscode from 'vscode';
import getKeybindingsServiceOverride from '@codingame/monaco-vscode-keybindings-service-override';
// this is required syntax highlighting
import '@codingame/monaco-vscode-java-default-extension';
import { MonacoEditorLanguageClientWrapper, UserConfig } from 'monaco-editor-wrapper';
import { MonacoEditorLanguageClientWrapper, WrapperConfig } from 'monaco-editor-wrapper';
import { useWorkerFactory } from 'monaco-editor-wrapper/workerFactory';
import { RegisteredFileSystemProvider, RegisteredMemoryFile, registerFileSystemOverlay } from '@codingame/monaco-vscode-files-service-override';
import { eclipseJdtLsConfig } from '../config.js';
Expand All @@ -28,42 +28,41 @@ export const runEclipseJdtLsClient = () => {
fileSystemProvider.registerFile(new RegisteredMemoryFile(helloJavaUri, helloJavaCode));
registerFileSystemOverlay(1, fileSystemProvider);

const userConfig: UserConfig = {
wrapperConfig: {
serviceConfig: {
userServices: {
...getKeybindingsServiceOverride(),
},
debugLogging: true
const userConfig: WrapperConfig = {
serviceConfig: {
userServices: {
...getKeybindingsServiceOverride(),
},
editorAppConfig: {
$type: 'extended',
codeResources: {
main: {
text: helloJavaCode,
uri: `${eclipseJdtLsConfig.basePath}/workspace/hello.java`
}
},
useDiffEditor: false,
userConfiguration: {
json: JSON.stringify({
'workbench.colorTheme': 'Default Dark Modern',
'editor.guides.bracketPairsHorizontal': 'active',
'editor.wordBasedSuggestions': 'off'
})
debugLogging: true
},
editorAppConfig: {
$type: 'extended',
codeResources: {
main: {
text: helloJavaCode,
uri: `${eclipseJdtLsConfig.basePath}/workspace/hello.java`
}
},
useDiffEditor: false,
userConfiguration: {
json: JSON.stringify({
'workbench.colorTheme': 'Default Dark Modern',
'editor.guides.bracketPairsHorizontal': 'active',
'editor.wordBasedSuggestions': 'off'
})
}

},
languageClientConfigs: {
java: {
languageId: 'java',
connection: {
configOptions: {
options: {
$type: 'WebSocketUrl',
url: 'ws://localhost:30003/jdtls'
}
},
languageClientOptions: {
clientOptions: {
documentSelector: ['java'],
workspaceFolder: {
index: 0,
Expand Down
46 changes: 22 additions & 24 deletions packages/examples/src/groovy/client/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import getKeybindingsServiceOverride from '@codingame/monaco-vscode-keybindings-service-override';
// this is required syntax highlighting
import '@codingame/monaco-vscode-groovy-default-extension';
import { MonacoEditorLanguageClientWrapper, UserConfig } from 'monaco-editor-wrapper';
import { MonacoEditorLanguageClientWrapper, WrapperConfig } from 'monaco-editor-wrapper';
import { groovyConfig } from '../config.js';
import { useWorkerFactory } from 'monaco-editor-wrapper/workerFactory';

Expand All @@ -24,37 +24,35 @@ import java.io.File;
File file = new File("E:/Example.txt");
`;

const userConfig: UserConfig = {
wrapperConfig: {
serviceConfig: {
userServices: {
...getKeybindingsServiceOverride(),
},
debugLogging: true
const userConfig: WrapperConfig = {
serviceConfig: {
userServices: {
...getKeybindingsServiceOverride(),
},
editorAppConfig: {
$type: 'extended',
codeResources: {
main: {
text: code,
fileExt: 'groovy'
}
},
useDiffEditor: false,
userConfiguration: {
json: JSON.stringify({
'workbench.colorTheme': 'Default Dark Modern',
'editor.guides.bracketPairsHorizontal': 'active',
'editor.wordBasedSuggestions': 'off'
})
debugLogging: true
},
editorAppConfig: {
$type: 'extended',
codeResources: {
main: {
text: code,
fileExt: 'groovy'
}
},
useDiffEditor: false,
userConfiguration: {
json: JSON.stringify({
'workbench.colorTheme': 'Default Dark Modern',
'editor.guides.bracketPairsHorizontal': 'active',
'editor.wordBasedSuggestions': 'off'
})
}
},
languageClientConfigs: {
groovy: {
languageId: 'groovy',
connection: {
configOptions: {
options: {
$type: 'WebSocketUrl',
url: `ws://localhost:${groovyConfig.port}${groovyConfig.path}`
}
Expand Down
48 changes: 23 additions & 25 deletions packages/examples/src/json/client/wrapperWs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import getKeybindingsServiceOverride from '@codingame/monaco-vscode-keybindings-service-override';
// this is required syntax highlighting
import '@codingame/monaco-vscode-json-default-extension';
import { MonacoEditorLanguageClientWrapper, UserConfig } from 'monaco-editor-wrapper';
import { MonacoEditorLanguageClientWrapper, WrapperConfig } from 'monaco-editor-wrapper';
import { useWorkerFactory } from 'monaco-editor-wrapper/workerFactory';

export const configureMonacoWorkers = () => {
Expand All @@ -24,38 +24,36 @@ const text = `{
"line_endings": {"value": "unix"}
}`;

export const jsonClientUserConfig: UserConfig = {
wrapperConfig: {
serviceConfig: {
userServices: {
...getKeybindingsServiceOverride(),
},
debugLogging: true
export const jsonClientUserConfig: WrapperConfig = {
serviceConfig: {
userServices: {
...getKeybindingsServiceOverride(),
},
editorAppConfig: {
$type: 'extended',
codeResources: {
main: {
text,
fileExt: 'json'
}
},
useDiffEditor: false,
userConfiguration: {
json: JSON.stringify({
'workbench.colorTheme': 'Default Dark Modern',
'editor.guides.bracketPairsHorizontal': 'active',
'editor.lightbulb.enabled': 'On',
'editor.wordBasedSuggestions': 'off'
})
debugLogging: true
},
editorAppConfig: {
$type: 'extended',
codeResources: {
main: {
text,
fileExt: 'json'
}
},
useDiffEditor: false,
userConfiguration: {
json: JSON.stringify({
'workbench.colorTheme': 'Default Dark Modern',
'editor.guides.bracketPairsHorizontal': 'active',
'editor.lightbulb.enabled': 'On',
'editor.wordBasedSuggestions': 'off'
})
}
},
languageClientConfigs: {
json: {
languageId: 'json',
connection: {
configOptions: {
options: {
$type: 'WebSocketUrl',
url: 'ws://localhost:30000/sampleServer',
startOptions: {
Expand Down
Loading

0 comments on commit 45c7fc3

Please sign in to comment.