cmd/golsp/integration/vscode: add language server client for testing
We've been using https://github.com/stamblerre/vscode-test-golsp to test the golsp. Ideally, we'd like to add integration tests with the major editors, so we're moving this basic extension into x/tools, with the intention of integration tests here. This is not meant to be used by any users of golsp; it is only for testing. Change-Id: I7c45e7c638311d29629ff6d3291332e68cf4621a Reviewed-on: https://go-review.googlesource.com/c/153438 Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
parent
1d424dbce8
commit
feaab9440b
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Launch Extension",
|
||||||
|
"type": "extensionHost",
|
||||||
|
"request": "launch",
|
||||||
|
"runtimeExecutable": "${execPath}",
|
||||||
|
"args": [
|
||||||
|
"--extensionDevelopmentPath=${workspaceFolder}"
|
||||||
|
],
|
||||||
|
"stopOnEntry": false,
|
||||||
|
"sourceMaps": true,
|
||||||
|
"outFiles": [
|
||||||
|
"${workspaceFolder}/out/**/*.js"
|
||||||
|
],
|
||||||
|
"preLaunchTask": "npm"
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
// Available variables which can be used inside of strings.
|
||||||
|
// ${workspaceFolder}: the root folder of the team
|
||||||
|
// ${file}: the current opened file
|
||||||
|
// ${fileBasename}: the current opened file's basename
|
||||||
|
// ${fileDirname}: the current opened file's dirname
|
||||||
|
// ${fileExtname}: the current opened file's extension
|
||||||
|
// ${cwd}: the current working directory of the spawned process
|
||||||
|
// A task runner that calls the Typescript compiler (tsc) and
|
||||||
|
// compiles the extension.
|
||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
// we want to run npm
|
||||||
|
"command": "npm",
|
||||||
|
// the command is a shell script
|
||||||
|
"type": "shell",
|
||||||
|
// show the output window only if unrecognized errors occur.
|
||||||
|
"presentation": {
|
||||||
|
"reveal": "silent"
|
||||||
|
},
|
||||||
|
// we run the custom script "compile" as defined in package.json
|
||||||
|
"args": [
|
||||||
|
"run",
|
||||||
|
"compile"
|
||||||
|
],
|
||||||
|
// The tsc compiler is started in watching mode
|
||||||
|
"isBackground": true,
|
||||||
|
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
|
||||||
|
"problemMatcher": "$tsc-watch"
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
# golsp testing extension
|
||||||
|
|
||||||
|
An extension for debugging the Go Language Server provided by
|
||||||
|
https://golang.org/x/tools/cmd/golsp. The code for this extension comes from
|
||||||
|
a combination of
|
||||||
|
https://github.com/Microsoft/vscode-extension-samples/blob/master/lsp-sample
|
||||||
|
and https://github.com/Microsoft/vscode-go.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
* Diagnostics (on file change)
|
||||||
|
* Completion (Ctrl + Space)
|
||||||
|
* Jump to definition (F12 or right-click -> Go to Definition)
|
||||||
|
* Signature help (Ctrl + Shift + Space)
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
To package the extension, run `vsce package` from this directory. To install
|
||||||
|
the extension, navigate to the "Extensions" panel in VSCode, and select
|
||||||
|
"Install from VSIX..." from the menu in the top right corner. Choose the
|
||||||
|
`golsp-1.0.0.vsix file` and reload VSCode.
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,52 @@
|
||||||
|
{
|
||||||
|
"name": "golsp",
|
||||||
|
"description": "Go Language Server Client for testing",
|
||||||
|
"author": "The Go authors",
|
||||||
|
"license": "SEE LICENSE IN ../../../../LICENSE",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://golang.org/x/tools"
|
||||||
|
},
|
||||||
|
"publisher": "golang",
|
||||||
|
"engines": {
|
||||||
|
"vscode": "^1.23.0"
|
||||||
|
},
|
||||||
|
"activationEvents": [
|
||||||
|
"onLanguage:go"
|
||||||
|
],
|
||||||
|
"main": "./out/extension",
|
||||||
|
"scripts": {
|
||||||
|
"vscode:prepublish": "tsc -p ./",
|
||||||
|
"compile": "tsc -watch -p ./",
|
||||||
|
"postinstall": "node ./node_modules/vscode/bin/install",
|
||||||
|
"lint": "node ./node_modules/tslint/bin/tslint ./src/*.ts"
|
||||||
|
},
|
||||||
|
"extensionDependencies": [],
|
||||||
|
"dependencies": {
|
||||||
|
"vscode-languageclient": "~4.3.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/mocha": "^5.2.5",
|
||||||
|
"@types/node": "^8.0.0",
|
||||||
|
"tslint": "^5.11.0",
|
||||||
|
"typescript": "^3.1.3",
|
||||||
|
"vscode": "^1.1.24"
|
||||||
|
},
|
||||||
|
"contributes": {
|
||||||
|
"configuration": {
|
||||||
|
"title": "Go LSP",
|
||||||
|
"properties": {
|
||||||
|
"golsp.flags": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"default": [],
|
||||||
|
"description": "Flags to pass to golsp",
|
||||||
|
"scope": "resource"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
// Copyright 2018 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
import fs = require('fs');
|
||||||
|
import lsp = require('vscode-languageclient');
|
||||||
|
import vscode = require('vscode');
|
||||||
|
import path = require('path');
|
||||||
|
|
||||||
|
export function activate(ctx: vscode.ExtensionContext): void {
|
||||||
|
let document = vscode.window.activeTextEditor.document;
|
||||||
|
let config = vscode.workspace.getConfiguration('golsp', document.uri);
|
||||||
|
let golspFlags: string[] = config['flags'];
|
||||||
|
let serverOptions:
|
||||||
|
lsp.ServerOptions = {command: getBinPath('golsp'), args: golspFlags};
|
||||||
|
let clientOptions: lsp.LanguageClientOptions = {
|
||||||
|
initializationOptions: {},
|
||||||
|
documentSelector: ['go'],
|
||||||
|
uriConverters: {
|
||||||
|
code2Protocol: (uri: vscode.Uri): string =>
|
||||||
|
(uri.scheme ? uri : uri.with({scheme: 'file'})).toString(),
|
||||||
|
protocol2Code: (uri: string) => vscode.Uri.parse(uri),
|
||||||
|
},
|
||||||
|
revealOutputChannelOn: lsp.RevealOutputChannelOn.Never,
|
||||||
|
};
|
||||||
|
const c = new lsp.LanguageClient('golsp', serverOptions, clientOptions);
|
||||||
|
c.onReady().then(() => {
|
||||||
|
const capabilities = c.initializeResult && c.initializeResult.capabilities;
|
||||||
|
if (!capabilities) {
|
||||||
|
return vscode.window.showErrorMessage(
|
||||||
|
'The language server is not able to serve any features at the moment.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ctx.subscriptions.push(c.start());
|
||||||
|
}
|
||||||
|
|
||||||
|
function getBinPath(toolName: string): string {
|
||||||
|
toolName = correctBinname(toolName);
|
||||||
|
let tool = findToolIn(toolName, 'PATH', false);
|
||||||
|
if (tool) {
|
||||||
|
return tool;
|
||||||
|
}
|
||||||
|
return findToolIn(toolName, 'GOPATH', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function findToolIn(
|
||||||
|
toolName: string, envVar: string, appendBinToPath: boolean): string {
|
||||||
|
let value = process.env[envVar];
|
||||||
|
if (value) {
|
||||||
|
let paths = value.split(path.delimiter);
|
||||||
|
for (let i = 0; i < paths.length; i++) {
|
||||||
|
let binpath = path.join(paths[i], appendBinToPath ? 'bin' : '', toolName);
|
||||||
|
if (fileExists(binpath)) {
|
||||||
|
return binpath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function fileExists(filePath: string): boolean {
|
||||||
|
try {
|
||||||
|
return fs.statSync(filePath).isFile();
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function correctBinname(toolName: string) {
|
||||||
|
if (process.platform === 'win32')
|
||||||
|
return toolName + '.exe';
|
||||||
|
else
|
||||||
|
return toolName;
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "commonjs",
|
||||||
|
"target": "es6",
|
||||||
|
"outDir": "out",
|
||||||
|
"rootDir": "src",
|
||||||
|
"lib": [
|
||||||
|
"es6"
|
||||||
|
],
|
||||||
|
"sourceMap": true
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"node_modules"
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"rules": {
|
||||||
|
"indent": [
|
||||||
|
true,
|
||||||
|
"tabs"
|
||||||
|
],
|
||||||
|
"semicolon": [
|
||||||
|
true,
|
||||||
|
"always"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue