Skip to content

Commit

Permalink
refactor: add LanguageCli enum
Browse files Browse the repository at this point in the history
  • Loading branch information
ls-infra committed Jan 16, 2024
1 parent bca54c2 commit 43690a7
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h3>Python language client and language server</h3>
<a href="packages/examples/python.html">Client for Python Pyright Language Server</a>
<h3>Groovy language client and language server</h3>
Please execute <b><code>npm run start:example:server:groovy</code></b> beforehand:<br>
<a href="packages/examples/groovy.html">Client for Node.js Language Server</a>
<a href="packages/examples/groovy.html">Client for Groovy Language Server</a>
<h3>Langium client and language server</h3>
<a href="packages/examples/statemachine_client.html">Client & Statemachine LS (Web Worker)</a><br>
Localizations: <a href="packages/examples/statemachine_client.html?locale=de">German</a> <a href="packages/examples/statemachine_client.html?locale=fr">French</a> and <a href="packages/examples/statemachine_client.html?locale=es">Spanish</a><br>
Expand Down
1 change: 1 addition & 0 deletions packages/examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
resources/themes
src/groovy/server/groovy-language-server-all.jar
9 changes: 8 additions & 1 deletion packages/examples/src/common/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
* ------------------------------------------------------------------------------------------ */
import * as cp from 'child_process';
import { ServerOptions } from 'ws';

export enum LanguageCli {
/** https://nodejs.org/api/cli.html */
node = 'node',
/** https://docs.oracle.com/en/java/javase/21/docs/specs/man/java.html */
java = 'java'
}
export interface LanguageServerRunConfig {
serverName: string;
pathName: string;
serverPort: number;
runCommand: string; // 'node', 'java' , etc.
runCommand: LanguageCli;
runCommandArgs: string[];
wsServerOptions: ServerOptions,
spawnOptions?: cp.SpawnOptions;
Expand Down
2 changes: 1 addition & 1 deletion packages/examples/src/groovy/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
* ------------------------------------------------------------------------------------------ */

export const groovyConfig = {
port: 3001,
port: 3002,
path: '/groovy'
};
3 changes: 2 additions & 1 deletion packages/examples/src/groovy/server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import { runLanguageServer } from '../../common/language-server-runner.js';
import { resolve } from 'path';
import { groovyConfig } from '../config.js';
import { LanguageCli } from '../../common/model.js';
export const runGroovyLanguageServer = (baseDir: string, relativeDir: string) => {
const processRunPath = resolve(baseDir, relativeDir);
runLanguageServer({
serverName: 'GROOVY',
pathName: groovyConfig.path,
serverPort: groovyConfig.port,
runCommand: 'java',
runCommand: LanguageCli.java,
runCommandArgs: [
'-jar',
processRunPath
Expand Down
3 changes: 2 additions & 1 deletion packages/examples/src/json/server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
* ------------------------------------------------------------------------------------------ */
import { runLanguageServer } from '../../common/language-server-runner.js';
import { resolve } from 'path';
import { LanguageCli } from '../../common/model.js';

export const runJsonServer = (baseDir: string, relativeDir: string) => {
const processRunPath = resolve(baseDir, relativeDir);
runLanguageServer({
serverName: 'JSON',
pathName: '/sampleServer',
serverPort: 30000,
runCommand: 'node',
runCommand: LanguageCli.node,
runCommandArgs: [
processRunPath,
'--stdio'
Expand Down
3 changes: 2 additions & 1 deletion packages/examples/src/python/server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
import { resolve } from 'path';
import { runLanguageServer } from '../../common/language-server-runner.js';
import { IncomingMessage } from 'http';
import { LanguageCli } from '../../common/model.js';

export const runPythonServer = (baseDir: string, relativeDir: string) => {
const processRunPath = resolve(baseDir, relativeDir);
runLanguageServer({
serverName: 'PYRIGHT',
pathName: '/pyright',
serverPort: 30001,
runCommand: 'node',
runCommand: LanguageCli.node,
runCommandArgs: [
processRunPath,
'--stdio'
Expand Down

0 comments on commit 43690a7

Please sign in to comment.