vscode-languageclient#ServerOptions TypeScript Examples
The following examples show how to use
vscode-languageclient#ServerOptions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: server.ts From plugin-vscode with Apache License 2.0 | 6 votes |
export function getServerOptions(ballerinaCmd: string): ServerOptions {
debug(`Using Ballerina CLI command '${ballerinaCmd}' for Language server.`);
let cmd = process.platform === 'win32' ? getConvertedPath(ballerinaCmd) : ballerinaCmd;
let args = ["start-language-server"];
let opt: ExecutableOptions = {};
opt.env = Object.assign({}, process.env);
if (process.env.LS_EXTENSIONS_PATH !== "") {
if (opt.env.BALLERINA_CLASSPATH_EXT) {
opt.env.BALLERINA_CLASSPATH_EXT += delimiter + process.env.LS_EXTENSIONS_PATH;
} else {
opt.env.BALLERINA_CLASSPATH_EXT = process.env.LS_EXTENSIONS_PATH;
}
}
if (process.env.LSDEBUG === "true") {
debug('Language Server is starting in debug mode.');
let debugPort = 5005;
opt.env.BAL_JAVA_DEBUG = debugPort;
opt.env.BAL_DEBUG_OPTS = "-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=" + debugPort + ",quiet=y";
}
if (process.env.LS_CUSTOM_CLASSPATH) {
args.push('--classpath', process.env.LS_CUSTOM_CLASSPATH);
}
return {
command: cmd,
args,
options: opt
};
}
Example #2
Source File: extension.ts From ui5-language-assistant with Apache License 2.0 | 5 votes |
export async function activate(context: ExtensionContext): Promise<void> {
const debugOptions = { execArgv: ["--nolazy", "--inspect=6009"] };
const serverOptions: ServerOptions = {
run: { module: SERVER_PATH, transport: TransportKind.ipc },
debug: {
module: SERVER_PATH,
transport: TransportKind.ipc,
options: debugOptions,
},
};
const meta = JSON.parse(
readFileSync(resolve(context.extensionPath, "package.json"), "utf8")
);
const logLevel = workspace.getConfiguration().get(LOGGING_LEVEL_CONFIG_PROP);
const initializationOptions: ServerInitializationOptions = {
modelCachePath: context.globalStoragePath,
publisher: meta.publisher,
name: meta.name,
// validation of the logLevel value is done on the language server process.
logLevel: logLevel as LogLevel,
};
const clientOptions: LanguageClientOptions = {
documentSelector: [{ scheme: "file", pattern: "**/*.{view,fragment}.xml" }],
synchronize: {
fileEvents: [workspace.createFileSystemWatcher("**/manifest.json")],
},
outputChannelName: meta.displayName,
initializationOptions: initializationOptions,
};
client = new LanguageClient(
"UI5LanguageAssistant",
"UI5 Language Assistant",
serverOptions,
clientOptions
);
client.start();
}
Example #3
Source File: extension.ts From dendron with GNU Affero General Public License v3.0 | 5 votes |
export function activate(context: ExtensionContext) {
// The server is implemented in node
let serverModule = context.asAbsolutePath(
path.join("server", "out", "server.js")
);
// TODO: don't hradcode
let expressModule = context.asAbsolutePath(
path.join("express-server", "dist", "src", "index.js")
);
// const { app: server } = require(expressModule);
// 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
let 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
let serverOptions: ServerOptions = {
run: { module: serverModule, transport: TransportKind.ipc },
debug: {
module: serverModule,
transport: TransportKind.ipc,
options: debugOptions,
},
};
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: [{ scheme: "file", language: "markdown" }],
synchronize: {
// Notify the server about file changes to '.clientrc files contained in the workspace
fileEvents: workspace.createFileSystemWatcher("**/.clientrc"),
},
};
// Create the language client and start the client.
client = new LanguageClient(
"languageServerExample",
"Language Server Example",
serverOptions,
clientOptions
);
// Start the client. This will also launch the server
client.start();
const port = 3000;
// server.listen(3000, () => {
// console.log("express server started");
// });
}
Example #4
Source File: lsp.ts From dendron with GNU Affero General Public License v3.0 | 5 votes |
export function startClient(opts: { context: ExtensionContext; port: number }) {
const { context, port } = opts;
// The server is implemented in node
const pathToDev = path.join(
__dirname,
"..",
"node_modules",
"@dendronhq",
"lsp-server",
"out",
"server.js"
);
let serverModule: string;
const isDev = fs.existsSync(pathToDev);
if (isDev) {
serverModule = pathToDev;
} else {
serverModule = context.asAbsolutePath(
path.join("dist", "lsp-server", "dist", "server.js")
);
}
const ctx = "startLSPClient";
Logger.info({ ctx, serverModule, isDev, msg: "starting client" });
// TODO: don't hradcode
// let expressModule = context.asAbsolutePath(
// path.join("express-server", "dist", "src", "index.js")
// );
// const { app: server } = require(expressModule);
// 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,
},
};
// Options to control the language client
const clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: [{ scheme: "file", language: "markdown" }],
synchronize: {
// Notify the server about file changes to '.clientrc files contained in the workspace
fileEvents: workspace.createFileSystemWatcher("dendron.yml"),
},
initializationOptions: {
wsRoot: path.dirname(DendronExtension.workspaceFile().fsPath),
port,
},
};
// Create the language client and start the client.
const client = new LanguageClient(
"dendron.lsp",
"Dendron LSP",
serverOptions,
clientOptions,
true
);
// Start the client. This will also launch the server
client.start();
// const port = 3000;
// server.listen(3000, () => {
// console.log("express server started");
// });
return { client };
}
Example #5
Source File: extension.ts From reach-ide with Eclipse Public License 2.0 | 5 votes |
export function activate(context: ExtensionContext) {
// The server is implemented in node
let serverModule = context.asAbsolutePath(
path.join('server', 'out', 'server.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
let 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
let serverOptions: ServerOptions = {
run: { module: serverModule, transport: TransportKind.ipc },
debug: {
module: serverModule,
transport: TransportKind.ipc,
options: debugOptions
}
};
terminal = window.createTerminal({ name: 'Reach IDE' });
const reachExecutablePath = workspace.getConfiguration().get('reachide.executableLocation') as string;
const wf = workspace.workspaceFolders[0].uri.path || '.';
const reachPath = (reachExecutablePath === './reach')
? path.join(wf, 'reach')
: reachExecutablePath;
registerCommands(context, reachPath);
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for Reach .rsh documents
documentSelector: [
{
pattern: '**/*.rsh',
scheme: 'file'
}
],
synchronize: {
// Notify the server about file changes to '.clientrc files contained in the workspace
fileEvents: workspace.createFileSystemWatcher('**/*.rsh')
}
};
// Create the language client and start the client.
client = new LanguageClient(
'reachide',
'Reach IDE',
serverOptions,
clientOptions
);
// Start the client. This will also launch the server
client.start();
initButtons(context);
// Inject association for .rsh file type
if (workspace.workspaceFolders !== undefined) {
rootFolder = url.fileURLToPath( workspace.workspaceFolders[0].uri.toString() );
}
associateRshFiles();
window.registerTreeDataProvider('reach-commands', new CommandsTreeDataProvider());
window.registerTreeDataProvider('reach-help', new HelpTreeDataProvider());
window.registerTreeDataProvider('reach-docs', new DocumentationTreeDataProvider());
}
Example #6
Source File: extension.ts From plugin-vscode with Apache License 2.0 | 4 votes |
init(_onBeforeInit: Function): Promise<void> {
// Register show logs command.
const showLogs = commands.registerCommand('ballerina.showLogs', () => {
outputChannel.show();
});
this.context!.subscriptions.push(showLogs);
try {
// Register pre init handlers.
this.registerPreInitHandlers();
// Check if ballerina home is set.
if (this.overrideBallerinaHome()) {
if (!this.getConfiguredBallerinaHome()) {
const message = "Trying to get ballerina version without setting ballerina home.";
sendTelemetryEvent(this, TM_EVENT_ERROR_INVALID_BAL_HOME_CONFIGURED, CMP_EXTENSION_CORE, message);
throw new AssertionError({
message: message
});
}
debug("Ballerina home is configured in settings.");
this.ballerinaHome = this.getConfiguredBallerinaHome();
}
// Validate the ballerina version.
const pluginVersion = this.extension.packageJSON.version.split('-')[0];
return this.getBallerinaVersion(this.ballerinaHome, this.overrideBallerinaHome()).then(runtimeVersion => {
this.ballerinaVersion = runtimeVersion.split('-')[0];
if (!this.overrideBallerinaHome()) {
const { home } = this.autoDetectBallerinaHome();
this.ballerinaHome = home;
}
log(`Plugin version: ${pluginVersion}\nBallerina version: ${this.ballerinaVersion}`);
this.sdkVersion.text = `Ballerina SDK: ${this.ballerinaVersion}`;
if (this.ballerinaVersion.match(SWAN_LAKE_REGEX)) {
this.isSwanLake = true;
} else if (this.ballerinaVersion.match(PREV_REGEX)) {
this.is12x = true;
}
if (!this.isSwanLake && !this.is12x) {
this.showMessageOldBallerina();
const message = `Ballerina version ${this.ballerinaVersion} is not supported.
Please use a compatible VSCode extension version.`;
sendTelemetryEvent(this, TM_EVENT_ERROR_OLD_BAL_HOME_DETECTED, CMP_EXTENSION_CORE, message);
throw new AssertionError({
message: message
});
}
// if Home is found load Language Server.
let serverOptions: ServerOptions;
serverOptions = getServerOptions(this.ballerinaCmd);
this.langClient = new ExtendedLangClient('ballerina-vscode', 'Ballerina LS Client', serverOptions,
this.clientOptions, false);
// Following was put in to handle server startup failures.
const disposeDidChange = this.langClient.onDidChangeState(stateChangeEvent => {
if (stateChangeEvent.newState === LS_STATE.Stopped) {
const message = "Couldn't establish language server connection.";
sendTelemetryEvent(this, TM_EVENT_EXTENSION_INI_FAILED, CMP_EXTENSION_CORE, message);
log(message);
this.showPluginActivationError();
}
});
let disposable = this.langClient.start();
this.langClient.onReady().then(() => {
disposeDidChange.dispose();
this.context!.subscriptions.push(disposable);
});
}, (reason) => {
sendTelemetryException(this, reason, CMP_EXTENSION_CORE);
throw new Error(reason);
}).catch(e => {
const msg = `Error when checking ballerina version. ${e.message}`;
sendTelemetryException(this, e, CMP_EXTENSION_CORE, msg);
this.telemetryReporter.dispose();
throw new Error(msg);
});
} catch (ex) {
const msg = "Error while activating plugin. " + (ex.message ? ex.message : ex);
// If any failure occurs while initializing show an error message
this.showPluginActivationError();
sendTelemetryException(this, ex, CMP_EXTENSION_CORE, msg);
this.telemetryReporter.dispose();
return Promise.reject(msg);
}
}
Example #7
Source File: extension.ts From sorbet-lsp with MIT License | 4 votes |
export function activate(context: ExtensionContext) {
let disposableClient: Disposable;
const startLanguageServer = () => {
let cmd = [];
let vsconfig = vscode.workspace.getConfiguration('sorbet');
const commandPath = vsconfig.commandPath || 'srb';
const useBundler = vsconfig.useBundler;
const useWatchman = vsconfig.useWatchman;
const bundlerPath = vsconfig.bundlerPath || 'bundle';
if (useBundler) {
cmd = cmd.concat([bundlerPath, 'exec', 'srb']);
} else {
cmd.push(commandPath);
}
cmd = cmd.concat(['tc', '--lsp', '--enable-all-experimental-lsp-features']);
if (!useWatchman) {
cmd.push('--disable-watchman');
}
const firstWorkspace = (workspace.workspaceFolders && workspace.workspaceFolders[0]) ? workspace.workspaceFolders[0].uri.fsPath : null;
if (!existsSync(`${firstWorkspace}/sorbet/config`)) {
vscode.window.showInformationMessage('Sorbet config not found. Sorbet server will not be started');
return;
}
const env = commonOptions(firstWorkspace);
// 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
let debugOptions = { execArgv: ['--nolazy', '--inspect=6009'] };
const serverOptions: ServerOptions = () => {
return new Promise((resolve) => {
let child = spawnWithBash(cmd, env);
child.stderr.on('data', (data: Buffer) => {
console.log(data.toString());
});
child.on('exit', (code, signal) => {
console.log('Sorbet exited with code', code, signal);
});
resolve(child);
});
}
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for plain text documents
documentSelector: [{ scheme: 'file', language: 'ruby' }],
synchronize: {
// Notify the server about changes to relevant files in the workspace
fileEvents: workspace.createFileSystemWatcher('{**/*.rb,**/*.gemspec,**/Gemfile}')
},
outputChannelName: 'Sorbet Language Server',
revealOutputChannelOn: RevealOutputChannelOn.Never
};
// Create the language client and start the client.
client = new LanguageClient(
'sorbetLanguageServer',
'Sorbet Language Server',
serverOptions,
clientOptions
);
// Start the client. This will also launch the server
disposableClient = client.start();
}
const restartLanguageServer = function (): Promise<void> {
return new Promise((resolve) => {
if (disposableClient) {
client.stop().then(() => {
disposableClient.dispose();
startLanguageServer();
resolve();
});
} else {
startLanguageServer();
resolve();
}
});
}
// Restart command
var disposableRestart = vscode.commands.registerCommand('sorbet.restart', () => {
restartLanguageServer().then(() => {
vscode.window.showInformationMessage('Sorbet server restarted.');
});
});
context.subscriptions.push(disposableRestart);
startLanguageServer();
}
Example #8
Source File: extension.ts From vscode-groovy-lint with GNU General Public License v3.0 | 4 votes |
export function activate(context: ExtensionContext) {
// Create diagnostics collection
diagnosticsCollection = vscode.languages.createDiagnosticCollection(DIAGNOSTICS_COLLECTION_NAME);
///////////////////////////////////////////////
/////////////// Server + client ///////////////
///////////////////////////////////////////////
// The server is implemented in node
let serverModule = context.asAbsolutePath(path.join('server', 'out', 'server.js'));
// If the extension is launched in debug mode then the debug server options are used
// Otherwise the run options are used
let serverOptions: ServerOptions = {
run: { module: serverModule, transport: TransportKind.ipc },
debug: {
module: serverModule,
transport: TransportKind.ipc,
options: {
execArgv: ['--nolazy', '--inspect=6009'],
env: { "DEBUG": "vscode-groovy-lint,npm-groovy-lint" }
}
}
};
// Options to control the language client
let clientOptions: LanguageClientOptions = {
// Register the server for groovy documents
documentSelector: [{ scheme: 'file', language: 'groovy' }],
diagnosticCollectionName: DIAGNOSTICS_COLLECTION_NAME,
progressOnInitialization: true,
synchronize: {
// Notify the server about file changes to '.clientrc files contained in the workspace
fileEvents: workspace.createFileSystemWatcher('**/.clientrc')
}
};
// Create the language client and start the client.
client = new LanguageClient(
'groovyLint',
'Groovy Lint',
serverOptions,
clientOptions
);
// Manage status bar item (with loading icon)
statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100);
statusBarItem.command = 'groovyLint.lint';
statusBarItem.text = 'GroovyLint $(clock~spin)';
statusBarItem.show();
client.registerProposedFeatures();
// Start the client. This will also launch the server
context.subscriptions.push(
client.start()
);
// Actions after client is ready
client.onReady().then(() => {
// Show status bar item to display & run groovy lint
refreshStatusBar();
// Manage status notifications
client.onNotification(StatusNotification.type, async (status) => {
await updateStatus(status);
});
// Open file in workspace when language server requests it
client.onNotification(OpenNotification.type, async (notifParams: any) => {
// Open textDocument from file path
if (notifParams.file) {
const openPath = vscode.Uri.parse("file:///" + notifParams.file); //A request file path
const doc = await vscode.workspace.openTextDocument(openPath);
await vscode.window.showTextDocument(doc, {
preserveFocus: true,
// eslint-disable-next-line eqeqeq
preview: (notifParams.preview != null) ? notifParams.preview : true
});
}
// Open textDocument from URI
else if (notifParams.uri) {
const openPath = vscode.Uri.parse(notifParams.uri); //A request file path
const doc = await vscode.workspace.openTextDocument(openPath);
await vscode.window.showTextDocument(doc, {
preserveFocus: true,
// eslint-disable-next-line eqeqeq
preview: (notifParams.preview != null) ? notifParams.preview : true
});
}
// Open url in external browser
else if (notifParams.url) {
await vscode.env.openExternal(notifParams.url);
}
});
// Refresh status bar when active tab changes
vscode.window.onDidChangeActiveTextEditor(async () => {
await refreshStatusBar();
await notifyDocumentToServer();
});
});
}