-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from davelopez/support_both_extension_modes
Support both extension modes
- Loading branch information
Showing
18 changed files
with
303 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,19 @@ | ||
import { ExtensionContext, Uri } from "vscode"; | ||
import { LanguageClientOptions } from "vscode-languageclient"; | ||
import { LanguageClient } from "vscode-languageclient/browser"; | ||
import { setupCommands } from "../commands/setup"; | ||
import { Constants } from "../constants"; | ||
import { CleanWorkflowDocumentProvider } from "../providers/cleanWorkflowDocumentProvider"; | ||
import { buildLanguageClientOptions, initExtension } from "../common"; | ||
|
||
export function activate(context: ExtensionContext) { | ||
console.log(`${context.extension.id} is now active in the web extension host.`); | ||
const client = buildWebLanguageClient(context); | ||
|
||
const client = startLanguageClient(context); | ||
|
||
setupProviders(context, client); | ||
|
||
setupCommands(context, client); | ||
initExtension(context, client); | ||
} | ||
|
||
export function deactivate() {} | ||
|
||
function startLanguageClient(context: ExtensionContext) { | ||
const documentSelector = [{ language: Constants.NATIVE_WORKFLOW_LANGUAGE_ID }]; | ||
|
||
// Options to control the language client | ||
const clientOptions: LanguageClientOptions = { | ||
documentSelector, | ||
synchronize: {}, | ||
initializationOptions: {}, | ||
}; | ||
|
||
const client = createWorkerLanguageClient(context, clientOptions); | ||
|
||
const disposable = client.start(); | ||
context.subscriptions.push(disposable); | ||
|
||
client.onReady().then(() => { | ||
console.log(`${context.extension.id} server is ready.`); | ||
}); | ||
return client; | ||
} | ||
|
||
function createWorkerLanguageClient(context: ExtensionContext, clientOptions: LanguageClientOptions) { | ||
const worker = createServerWorker(context); | ||
function buildWebLanguageClient(context: ExtensionContext) { | ||
const clientOptions: LanguageClientOptions = buildLanguageClientOptions(); | ||
const serverPath = Uri.joinPath(context.extensionUri, "server/dist/web/nativeServer.js"); | ||
const worker = new Worker(serverPath.toString()); | ||
return new LanguageClient("galaxy-workflow-language-client-native", "Galaxy Workflows LS", clientOptions, worker); | ||
} | ||
|
||
function createServerWorker(context: ExtensionContext) { | ||
// The worker main file implements the language server. | ||
const serverMain = Uri.joinPath(context.extensionUri, "server/dist/browserServerMain.js"); | ||
const worker = new Worker(serverMain.toString()); | ||
return worker; | ||
} | ||
|
||
function setupProviders(context: ExtensionContext, client: LanguageClient) { | ||
CleanWorkflowDocumentProvider.register(context, client); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ExtensionContext } from "vscode"; | ||
import { CommonLanguageClient, LanguageClientOptions } from "vscode-languageclient"; | ||
import { setupCommands } from "./commands/setup"; | ||
import { Constants } from "./constants"; | ||
import { CleanWorkflowDocumentProvider } from "./providers/cleanWorkflowDocumentProvider"; | ||
|
||
export function buildLanguageClientOptions() { | ||
const documentSelector = [{ language: Constants.NATIVE_WORKFLOW_LANGUAGE_ID }]; | ||
|
||
// Options to control the language client | ||
const clientOptions: LanguageClientOptions = { | ||
documentSelector, | ||
synchronize: {}, | ||
initializationOptions: {}, | ||
}; | ||
return clientOptions; | ||
} | ||
|
||
export function initExtension(context: ExtensionContext, client: CommonLanguageClient) { | ||
setupProviders(context, client); | ||
setupCommands(context, client); | ||
|
||
const disposable = client.start(); | ||
context.subscriptions.push(disposable); | ||
|
||
client.onReady().then(() => { | ||
console.log(`${context.extension.id} server is ready.`); | ||
}); | ||
} | ||
|
||
function setupProviders(context: ExtensionContext, client: CommonLanguageClient) { | ||
CleanWorkflowDocumentProvider.register(context, client); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import * as path from "path"; | ||
import { ExtensionContext } from "vscode"; | ||
import { LanguageClientOptions } from "vscode-languageclient"; | ||
import { LanguageClient, ServerOptions, TransportKind } from "vscode-languageclient/node"; | ||
import { buildLanguageClientOptions, initExtension } from "./common"; | ||
|
||
export function activate(context: ExtensionContext) { | ||
const client = buildLanguageClient(context); | ||
|
||
initExtension(context, client); | ||
} | ||
|
||
export function deactivate() {} | ||
|
||
function buildLanguageClient(context: ExtensionContext) { | ||
const clientOptions: LanguageClientOptions = buildLanguageClientOptions(); | ||
const serverOptions: ServerOptions = buildServerOptions(context); | ||
return new LanguageClient( | ||
"galaxy-workflow-language-client-native", | ||
"Galaxy Workflows LS", | ||
serverOptions, | ||
clientOptions | ||
); | ||
} | ||
|
||
function buildServerOptions(context: ExtensionContext) { | ||
// The server is implemented in node | ||
const serverModule = context.asAbsolutePath(path.join("server", "dist", "nativeServer.js")); | ||
// The debug options for the server | ||
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging | ||
const debugOptions = { execArgv: ["--nolazy", "--inspect=6009"] }; | ||
|
||
// If the extension is launched in debug mode then the debug server options are used | ||
// Otherwise the run options are used | ||
const serverOptions: ServerOptions = { | ||
run: { module: serverModule, transport: TransportKind.ipc }, | ||
debug: { | ||
module: serverModule, | ||
transport: TransportKind.ipc, | ||
options: debugOptions, | ||
}, | ||
}; | ||
return serverOptions; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
"WebWorker" | ||
], | ||
"rootDir": "src", | ||
"sourceMap": true | ||
"sourceMap": true, | ||
}, | ||
"include": [ | ||
"src" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* 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 nodeExtensionConfig = withDefaults({ | ||
context: path.join(__dirname), | ||
mode: "none", | ||
target: "node", // regular extensions run in a node context | ||
entry: { | ||
extension: "./src/extension.ts", | ||
}, | ||
output: { | ||
filename: "[name].js", | ||
path: path.join(__dirname, "dist"), | ||
libraryTarget: "commonjs", | ||
}, | ||
}); | ||
|
||
/** @type WebpackConfig */ | ||
const webExtensionConfig = withDefaults({ | ||
context: path.join(__dirname), | ||
mode: "none", | ||
target: "webworker", // web extensions run in a webworker context | ||
entry: { | ||
extension: "./src/browser/extension.ts", | ||
}, | ||
output: { | ||
filename: "[name].js", | ||
path: path.join(__dirname, "dist", "web"), | ||
libraryTarget: "commonjs", | ||
}, | ||
}); | ||
|
||
module.exports = [nodeExtensionConfig, webExtensionConfig]; |
Oops, something went wrong.