Skip to content

Commit

Permalink
Add NPM workspaces for language servers
Browse files Browse the repository at this point in the history
Reorganize the server project into a monorepo using NPM workspaces.
It allows to split each workflow language server on its own project and reuse/share local packages.
  • Loading branch information
davelopez committed Jun 18, 2022
1 parent ac2b551 commit 6522261
Show file tree
Hide file tree
Showing 51 changed files with 434 additions and 132 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"request": "attach",
"port": 6009,
"sourceMapPathOverrides": {
"webpack://?:*/*": "${workspaceFolder}/server/*"
"webpack://?:*/*": "${workspaceFolder}/server/gx-workflow-ls-native/*"
}
},
{
Expand All @@ -48,7 +48,7 @@
"request": "attach",
"port": 6010,
"sourceMapPathOverrides": {
"webpack://?:*/*": "${workspaceFolder}/server/*"
"webpack://?:*/*": "${workspaceFolder}/server/gx-workflow-ls-format2/*"
}
},
{
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"gitlens.advanced.blame.customArguments": ["--ignore-revs-file", ".git-blame-ignore-revs"]
"gitlens.advanced.blame.customArguments": ["--ignore-revs-file", ".git-blame-ignore-revs"],
"typescript.tsdk": "node_modules/typescript/lib"
}
4 changes: 2 additions & 2 deletions client/src/browser/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { Constants } from "../common/constants";
export function activate(context: ExtensionContext): void {
const nativeLanguageClient = createWebWorkerLanguageClient(
Constants.NATIVE_WORKFLOW_LANGUAGE_ID,
Uri.joinPath(context.extensionUri, "server/dist/web/nativeServer.js")
Uri.joinPath(context.extensionUri, "server/gx-workflow-ls-native/dist/web/nativeServer.js")
);
const gxFormat2LanguageClient = createWebWorkerLanguageClient(
Constants.GXFORMAT2_WORKFLOW_LANGUAGE_ID,
Uri.joinPath(context.extensionUri, "server/dist/web/gxFormat2Server.js")
Uri.joinPath(context.extensionUri, "server/gx-workflow-ls-format2/dist/web/gxFormat2Server.js")
);

initExtension(context, nativeLanguageClient, gxFormat2LanguageClient);
Expand Down
4 changes: 1 addition & 3 deletions client/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ function startLanguageClient(context: ExtensionContext, languageClient: CommonLa
context.subscriptions.push(disposable);

languageClient.onReady().then(() => {
console.log(
`${context.extension.id} ${languageClient.clientOptions.documentSelector[0].toString()} server is ready.`
);
console.log(`${context.extension.id} ${languageClient.outputChannel.name} server is ready.`);
});
}

Expand Down
6 changes: 4 additions & 2 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ function buildNodeLanguageClient(languageId: string, serverOptions: ServerOption

function buildNativeServerOptions(context: ExtensionContext): ServerOptions {
// The server is implemented in node
const serverModule = context.asAbsolutePath(path.join("server", "dist", "nativeServer.js"));
const serverModule = context.asAbsolutePath(path.join("server", "gx-workflow-ls-native", "dist", "nativeServer.js"));
const debugPort = 6009;
return buildBasicNodeServerOptions(serverModule, debugPort);
}

function buildGxFormat2ServerOptions(context: ExtensionContext): ServerOptions {
// The server is implemented in node
const serverModule = context.asAbsolutePath(path.join("server", "dist", "gxFormat2Server.js"));
const serverModule = context.asAbsolutePath(
path.join("server", "gx-workflow-ls-format2", "dist", "gxFormat2Server.js")
);
const debugPort = 6010;
return buildBasicNodeServerOptions(serverModule, debugPort);
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@
"lint": "eslint ./client/src ./server/src --ext .ts,.tsx",
"format": "prettier --write .",
"clean": "rimraf client/dist && rimraf server/dist",
"compile": "npm run clean && webpack --config ./client/webpack.config.js && webpack --config ./server/webpack.config.js",
"compile-servers": "cd server && npm run compile",
"compile": "npm run clean && webpack --config ./client/webpack.config.js && npm run compile-servers",
"vscode:prepublish": "npm run compile",
"watch": "concurrently --kill-others \"npm run watch-server\" \"npm run watch-client\"",
"watch-server": "cd server && npm run watch",
Expand Down
13 changes: 13 additions & 0 deletions server/gx-workflow-ls-format2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "gx-workflow-ls-format2",
"version": "0.1.0",
"description": "Language server implementation for Galaxy gxformat2 (YAML) workflows.",
"author": "davelopez",
"license": "MIT",
"dependencies": {
"@gxwf/server-common": "*",
"@gxwf/yaml-language-service": "*"
},
"devDependencies": {},
"scripts": {}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createConnection, BrowserMessageReader, BrowserMessageWriter } from "vscode-languageserver/browser";
import { GalaxyWorkflowLanguageServer } from "../../common/server";
import { GalaxyWorkflowLanguageServer } from "@gxwf/server-common/src/server";
import { GxFormat2WorkflowLanguageService } from "../languageService";

const messageReader = new BrowserMessageReader(self);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ObjectASTNode } from "vscode-json-languageservice";
import { TextDocument, Range, Position, ASTNode, WorkflowDocument } from "../common/languageTypes";
import { TextDocument, Range, Position, ASTNode, WorkflowDocument } from "@gxwf/server-common/src/languageTypes";

/**
* This class provides information about a gxformat2 workflow document structure.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ import {
Hover,
CompletionList,
Diagnostic,
} from "../common/languageTypes";
} from "@gxwf/server-common/src/languageTypes";
import { LanguageService, getLanguageService } from "@gxwf/yaml-language-service/src/yamlLanguageService";
import { GxFormat2WorkflowDocument } from "./gxFormat2WorkflowDocument";

/**
* A wrapper around the YAML Language Service to support language features
* for gxformat2 Galaxy workflow files.
*/
export class GxFormat2WorkflowLanguageService extends WorkflowLanguageService {
private _yamlLanguageService: LanguageService;
constructor() {
super();
this._yamlLanguageService = getLanguageService();
}

public override parseWorkflowDocument(document: TextDocument): WorkflowDocument {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createConnection } from "vscode-languageserver/node";
import { GalaxyWorkflowLanguageServer } from "../../common/server";
import { GalaxyWorkflowLanguageServer } from "@gxwf/server-common/src/server";
import { GxFormat2WorkflowLanguageService } from "../languageService";

const connection = createConnection();
Expand Down
12 changes: 12 additions & 0 deletions server/gx-workflow-ls-format2/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "es2019",
"lib": ["ES2019", "WebWorker"],
"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,
"esModuleInterop": true,
"sourceMap": true,
"strict": true
}
}
45 changes: 45 additions & 0 deletions server/gx-workflow-ls-format2/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */

//@ts-check
/** @typedef {import('webpack').Configuration} WebpackConfig **/

//@ts-check
"use strict";

const withDefaults = require("../../shared.webpack.config");
const path = require("path");

/** @type WebpackConfig */
const nodeGxFormat2ServerConfig = withDefaults({
mode: "none",
context: path.join(__dirname),
target: "node", // regular extensions run in node context
entry: {
gxFormat2Server: "./src/node/server.ts",
},
output: {
filename: "[name].js",
path: path.join(__dirname, "dist"),
libraryTarget: "var",
library: "serverExportVar",
},
});

/** @type WebpackConfig */
const browserGxFormat2ServerConfig = withDefaults({
mode: "none",
context: path.join(__dirname),
target: "webworker", // web extensions run in a webworker context
entry: {
gxFormat2Server: "./src/browser/server.ts",
},
output: {
filename: "[name].js",
path: path.join(__dirname, "dist", "web"),
libraryTarget: "var",
library: "serverExportVar",
},
});

module.exports = [nodeGxFormat2ServerConfig, browserGxFormat2ServerConfig];
15 changes: 15 additions & 0 deletions server/gx-workflow-ls-native/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "gx-workflow-ls-native",
"version": "0.1.0",
"description": "Language server implementation for Galaxy native (JSON) workflows.",
"author": "davelopez",
"license": "MIT",
"dependencies": {
"@gxwf/server-common": "*"
},
"scripts": {
"webpack": "webpack",
"watch": "webpack --watch --progress",
"test-unit": "jest"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createConnection, BrowserMessageReader, BrowserMessageWriter } from "vscode-languageserver/browser";
import { GalaxyWorkflowLanguageServer } from "../../common/server";
import { NativeWorkflowLanguageService } from "../languageService";
import { GalaxyWorkflowLanguageServer } from "@gxwf/server-common/src/server";

const messageReader = new BrowserMessageReader(self);
const messageWriter = new BrowserMessageWriter(self);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ASTNode } from "../common/languageTypes";
import { ASTNode } from "@gxwf/server-common/src/languageTypes";

export function getPathSegments(path: string): string[] | null {
const segments = path.split(/[/.]/);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
TextEdit,
WorkflowDocument,
WorkflowLanguageService,
} from "../common/languageTypes";
} from "@gxwf/server-common/src/languageTypes";
import NativeWorkflowSchema from "../../../workflow-languages/schemas/native.schema.json";
import { NativeWorkflowDocument } from "./nativeWorkflowDocument";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { JSONDocument, ObjectASTNode } from "vscode-json-languageservice";
import { getPropertyNodeFromPath } from "./jsonUtils";
import { TextDocument, Range, Position, ASTNode, WorkflowDocument } from "../common/languageTypes";
import { TextDocument, Range, Position, ASTNode, WorkflowDocument } from "@gxwf/server-common/src/languageTypes";

/**
* This class provides information about a Native workflow document structure.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createConnection } from "vscode-languageserver/node";
import { GalaxyWorkflowLanguageServer } from "../../common/server";
import { GalaxyWorkflowLanguageServer } from "@gxwf/server-common/src/server";
import { NativeWorkflowLanguageService } from "../languageService";

const connection = createConnection();
Expand Down
13 changes: 13 additions & 0 deletions server/gx-workflow-ls-native/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "es2019",
"lib": ["ES2019", "WebWorker"],
"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,
"esModuleInterop": true,
"sourceMap": true,
"strict": true,
"rootDirs": ["src"]
}
}
47 changes: 47 additions & 0 deletions server/gx-workflow-ls-native/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */

//@ts-check
/** @typedef {import('webpack').Configuration} WebpackConfig **/

//@ts-check
"use strict";

const withDefaults = require("../../shared.webpack.config");
const path = require("path");

/** Native (JSON) Server */

/** @type WebpackConfig */
const nodeNativeServerConfig = withDefaults({
mode: "none",
context: path.join(__dirname),
target: "node", // regular extensions run in node context
entry: {
nativeServer: "./src/node/server.ts",
},
output: {
filename: "[name].js",
path: path.join(__dirname, "dist"),
libraryTarget: "var",
library: "serverExportVar",
},
});

/** @type WebpackConfig */
const browserNativeServerConfig = withDefaults({
mode: "none",
context: path.join(__dirname),
target: "webworker", // web extensions run in a webworker context
entry: {
nativeServer: "./src/browser/server.ts",
},
output: {
filename: "[name].js",
path: path.join(__dirname, "dist", "web"),
libraryTarget: "var",
library: "serverExportVar",
},
});

module.exports = [nodeNativeServerConfig, browserNativeServerConfig];
Loading

0 comments on commit 6522261

Please sign in to comment.