Merge pull request #2684 from matklad/refactor-frontend

Refactor frontend
This commit is contained in:
Aleksey Kladov 2019-12-30 11:49:04 +01:00 committed by GitHub
commit 0c371d2128
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 162 additions and 1667 deletions

View file

@ -67,14 +67,7 @@ jobs:
with:
node-version: 12.x
- name: Install xvfb
run: sudo apt-get install xvfb
- run: npm ci
working-directory: ./editors/code
- run: npm run vscode:prepublish
- run: npm run package --scripts-prepend-node-path
working-directory: ./editors/code
- run: xvfb-run --auto-servernum npm run travis
working-directory: ./editors/code
- name: Cleanup xvfb
uses: bcomnes/cleanup-xvfb@v1

339
.vscode/launch.json vendored
View file

@ -5,19 +5,33 @@
"version": "0.2.0",
"configurations": [
{
"name": "Debug Extension",
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/editors/code",
"--disable-extensions"
"--extensionDevelopmentPath=${workspaceFolder}/editors/code"
],
"outFiles": [
"${workspaceFolder}/editors/code/out/**/*.js"
],
"preLaunchTask": "Build Extension"
},
{
"name": "Run Extension (Dev Server)",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/editors/code"
],
"outFiles": [
"${workspaceFolder}/editors/code/out/**/*.js"
],
"preLaunchTask": "Build Extension",
"env": {
"__RA_LSP_SERVER_DEBUG": "${workspaceFolder}/target/debug/ra_lsp_server"
},
"outFiles": ["${workspaceFolder}/editors/code/bundle/**/*.js"],
"preLaunchTask": "Build All"
}
},
{
"name": "Debug Lsp Server",
@ -25,316 +39,9 @@
"request": "attach",
"program": "${workspaceFolder}/target/debug/ra_lsp_server",
"pid": "${command:pickMyProcess}",
"sourceLanguages": ["rust"]
"sourceLanguages": [
"rust"
]
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'gen_lsp_server'",
"cargo": {
"args": ["test", "--no-run", "--lib", "--package=gen_lsp_server"],
"filter": {
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'ra_analysis'",
"cargo": {
"args": ["test", "--no-run", "--lib", "--package=ra_analysis"],
"filter": {
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug test 'tests'",
"cargo": {
"args": ["build", "--test=tests", "--package=ra_analysis"],
"filter": {
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in test 'tests'",
"cargo": {
"args": ["test", "--no-run", "--test=tests", "--package=ra_analysis"],
"filter": {
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'ra_hir'",
"cargo": {
"args": ["test", "--no-run", "--lib", "--package=ra_hir"],
"filter": {
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'ra_db'",
"cargo": {
"args": ["test", "--no-run", "--lib", "--package=ra_db"],
"filter": {
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'ra_editor'",
"cargo": {
"args": ["test", "--no-run", "--lib", "--package=ra_editor"],
"filter": {
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'ra_syntax'",
"cargo": {
"args": ["test", "--no-run", "--lib", "--package=ra_syntax"],
"filter": {
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug test 'test'",
"cargo": {
"args": ["build", "--test=test", "--package=ra_syntax"],
"filter": {
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in test 'test'",
"cargo": {
"args": ["test", "--no-run", "--test=test", "--package=ra_syntax"],
"filter": {
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'test_utils'",
"cargo": {
"args": ["test", "--no-run", "--lib", "--package=test_utils"],
"filter": {
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'ra_cli'",
"cargo": {
"args": ["build", "--bin=ra_cli", "--package=ra_cli"],
"filter": {
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'ra_cli'",
"cargo": {
"args": ["test", "--no-run", "--bin=ra_cli", "--package=ra_cli"],
"filter": {
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'tools'",
"cargo": {
"args": ["test", "--no-run", "--lib", "--package=tools"],
"filter": {
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'tools'",
"cargo": {
"args": ["build", "--bin=tools", "--package=tools"],
"filter": {
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'tools'",
"cargo": {
"args": ["test", "--no-run", "--bin=tools", "--package=tools"],
"filter": {
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug test 'cli'",
"cargo": {
"args": ["build", "--test=cli", "--package=tools"],
"filter": {
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in test 'cli'",
"cargo": {
"args": ["test", "--no-run", "--test=cli", "--package=tools"],
"filter": {
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in library 'ra_lsp_server'",
"cargo": {
"args": ["test", "--no-run", "--lib", "--package=ra_lsp_server"],
"filter": {
"kind": "lib"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'ra_lsp_server'",
"cargo": {
"args": ["build", "--bin=ra_lsp_server", "--package=ra_lsp_server"],
"filter": {
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'ra_lsp_server'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin=ra_lsp_server",
"--package=ra_lsp_server"
],
"filter": {
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug test 'heavy_tests'",
"cargo": {
"args": ["build", "--test=heavy_tests", "--package=ra_lsp_server"],
"filter": {
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in test 'heavy_tests'",
"cargo": {
"args": [
"test",
"--no-run",
"--test=heavy_tests",
"--package=ra_lsp_server"
],
"filter": {
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
}

56
.vscode/tasks.json vendored
View file

@ -4,57 +4,23 @@
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "compile",
"label": "Build Extension",
"group": "build",
"type": "npm",
"script": "watch",
"path": "editors/code/",
"problemMatcher": {
"owner": "typescript",
"pattern": "$tsc",
"fileLocation": [
"relative",
"${workspaceRoot}/editors/code"
]
"base": "$tsc-watch",
"fileLocation": ["relative", "${workspaceFolder}/editors/code/"]
},
"path": "editors/code/"
"isBackground": true,
},
{
"label": "Build Lsp",
"label": "Build Server",
"group": "build",
"type": "shell",
"command": "cargo build",
"command": "cargo build --package ra_lsp_server",
"problemMatcher": "$rustc"
},
{
"label": "Build All",
"group": "build",
"dependsOn": [
"Build Extension",
"Build Lsp"
],
"problemMatcher": []
},
{
"label": "cargo watch",
"group": "build",
"isBackground": true,
"type": "shell",
"command": "cargo",
"args": [
"watch"
],
"problemMatcher": "$rustc-watch"
},
{
"label": "cargo watch tests",
"group": "build",
"isBackground": true,
"type": "shell",
"command": "cargo",
"args": [
"watch",
"-x",
"check --tests"
],
"problemMatcher": "$rustc-watch"
}
]
}
}

View file

@ -1,2 +0,0 @@
node_modules/
.vscode-test/

View file

@ -1,31 +0,0 @@
// A launch configuration that compiles the extension and then opens it inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"preLaunchTask": "npm: watch"
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"${workspaceFolder}/src/test/",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test"
],
"outFiles": ["${workspaceFolder}/out/test/**/*.js"],
"preLaunchTask": "npm: watch"
}
]
}

View file

@ -1,11 +0,0 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
}

View file

@ -1,20 +0,0 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": {
"reveal": "never"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

View file

@ -1,9 +1,4 @@
.vscode/**
.vscode-test/**
out/**
src/**
.gitignore
tsconfig.json
vsc-extension-quickstart.md
tslint.json
node_modules/**
**
!out/extension.js
!package.json
!package-lock.json

File diff suppressed because it is too large Load diff

View file

@ -16,48 +16,26 @@
"vscode": "^1.41.0"
},
"scripts": {
"vscode:prepublish": "npm run compile",
"vscode:prepublish": "rollup -c",
"package": "vsce package",
"compile": "rollup -c",
"watch": "tsc -watch -p ./",
"fix": "prettier **/*.{json,ts} --write && tslint --project . --fix",
"lint": "tslint --project .",
"prettier": "prettier **/*.{json,ts}",
"test": "tsc -p . && node ./out/test/runTest.js",
"travis": "npm run compile && npm run test && npm run lint && npm run prettier -- --write && git diff --exit-code"
},
"prettier": {
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "all"
"watch": "tsc -watch -p ./"
},
"dependencies": {
"lookpath": "^1.0.4",
"jsonc-parser": "^2.1.0",
"seedrandom": "^3.0.5",
"vscode-languageclient": "^6.0.0-next.9",
"jsonc-parser": "^2.1.0"
"vscode-languageclient": "^6.0.0-next.9"
},
"devDependencies": {
"@types/glob": "^7.1.1",
"@types/mocha": "^5.2.7",
"rollup": "^1.27.14",
"@rollup/plugin-commonjs": "^11.0.0",
"@rollup/plugin-node-resolve": "^6.0.0",
"@rollup/plugin-typescript": "^2.0.1",
"typescript": "^3.7.3",
"tslib": "^1.10.0",
"vsce": "^1.71.0",
"@types/node": "^12.12.21",
"@types/seedrandom": "^2.4.28",
"@types/vscode": "^1.41.0",
"glob": "^7.1.6",
"mocha": "^6.2.2",
"prettier": "^1.19.1",
"rollup": "^1.27.13",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-typescript": "^1.0.1",
"shx": "^0.3.1",
"tslint": "^5.20.1",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.0.1",
"typescript": "^3.7.3",
"vsce": "^1.71.0",
"vscode-test": "^1.3.0"
"@types/vscode": "^1.41.0"
},
"activationEvents": [
"onLanguage:rust",
@ -65,7 +43,7 @@
"onCommand:rust-analyzer.collectGarbage",
"workspaceContains:**/Cargo.toml"
],
"main": "./bundle/extension",
"main": "./out/extension",
"contributes": {
"taskDefinitions": [
{

View file

@ -1,30 +1,25 @@
import typescript from 'rollup-plugin-typescript';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import sourcemaps from 'rollup-plugin-sourcemaps'
import typescript from '@rollup/plugin-typescript';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import nodeBuiltins from 'builtin-modules';
export default {
input: './src/extension.ts',
input: 'src/extension.ts',
plugins: [
typescript(),
sourcemaps(),
resolve(),
resolve({
preferBuiltins: true
}),
commonjs({
namedExports: {
// squelch missing import warnings
'vscode-languageclient': [ 'CreateFile', 'RenameFile' ]
'vscode-languageclient': ['CreateFile', 'RenameFile']
}
}),
],
// keep these as require() calls, bundle the rest
external: [
...nodeBuiltins,
'vscode',
})
],
external: [...nodeBuiltins, 'vscode'],
output: {
file: './bundle/extension.js',
sourcemap: true,
format: 'cjs',
file: './out/extension.js',
format: 'cjs'
}
};

View file

@ -1,5 +1,4 @@
import { lookpath } from 'lookpath';
import { homedir, platform } from 'os';
import { homedir } from 'os';
import * as lc from 'vscode-languageclient';
import { window, workspace } from 'vscode';
@ -29,15 +28,6 @@ export class Server {
}
const command = expandPathResolving(this.config.raLspServerPath);
// FIXME: remove check when the following issue is fixed:
// https://github.com/otiai10/lookpath/issues/4
if (platform() !== 'win32') {
if (!(await lookpath(command))) {
throw new Error(
`Cannot find rust-analyzer server \`${command}\` in PATH.`,
);
}
}
const run: lc.Executable = {
command,
options: { cwd: folder },

View file

@ -1,22 +0,0 @@
import * as path from 'path';
import { runTests } from 'vscode-test';
async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
// The path to the extension test runner script
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './utils/index');
// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath });
} catch (err) {
process.exit(1);
}
}
main();

View file

@ -1,49 +0,0 @@
//
// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING
//
// This file is providing the test runner to use when running extension tests.
// By default the test runner in use is Mocha based.
//
// You can provide your own test runner if you want to override it by exporting
// a function run(testRoot: string, clb: (error:Error) => void) that the extension
// host can call to run the tests. The test runner is expected to use console.log
// to report the results back to the caller. When the tests are finished, return
// a possible error to the callback or null if none.
import * as glob from 'glob';
import * as Mocha from 'mocha';
import * as path from 'path';
export function run(): Promise<void> {
// Create the mocha test
const mocha = new Mocha({
ui: 'bdd',
});
mocha.useColors(true);
const testsRoot = __dirname;
return new Promise((c, e) => {
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
if (err) {
return e(err);
}
// Add files to the test suite
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
try {
// Run the mocha test
mocha.run(failures => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
} else {
c();
}
});
} catch (err) {
e(err);
}
});
});
}

View file

@ -3,7 +3,9 @@
"module": "commonjs",
"target": "es2018",
"outDir": "out",
"lib": ["es2018"],
"lib": [
"es2018"
],
"sourceMap": true,
"rootDir": "src",
"strict": true,
@ -12,5 +14,7 @@
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"exclude": ["node_modules", ".vscode-test"]
"exclude": [
"node_modules"
]
}

View file

@ -1,15 +0,0 @@
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended",
"tslint-config-prettier",
"tslint-plugin-prettier"
],
"rules": {
"interface-name": false,
"prettier": true,
"object-literal-sort-keys": false,
// Allow `_bar` to sort with tsc's `noUnusedParameters` option
"variable-name": [true, "allow-leading-underscore"]
}
}