you better run

This commit is contained in:
Aleksey Kladov 2018-08-27 22:52:43 +03:00
parent 5751815314
commit 422efe59af
13 changed files with 2654 additions and 2633 deletions

9
code/.gitignore vendored
View file

@ -1,7 +1,4 @@
target out
index.node node_modules
artifacts.json .vscode-test/
*.vsix *.vsix
out/*
node_modules/*
log/*

View file

@ -1,4 +0,0 @@
runtime = electron
target = 1.7.9
target_arch = x64
disturl = https://atom.io/download/atom-shell

View file

@ -1,22 +1,36 @@
// 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
{ {
// 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", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "Launch Extension", "name": "Extension",
"type": "extensionHost", "type": "extensionHost",
"request": "launch", "request": "launch",
"runtimeExecutable": "${execPath}", "runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath='./'"], "args": [
"env": { "--extensionDevelopmentPath=${workspaceFolder}"
"RUST_LOG": "m=trace" ],
}, "outFiles": [
"stopOnEntry": false, "${workspaceFolder}/out/**/*.js"
"sourceMaps": true, ],
"outFiles": [ "./out/src/**/*.js" ], "preLaunchTask": "npm: watch"
"preLaunchTask": "npm"
}, },
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "npm: watch"
}
] ]
} }

View file

@ -1,10 +1,11 @@
// Place your settings in this file to overwrite default and user settings. // Place your settings in this file to overwrite default and user settings.
{ {
"files.exclude": { "files.exclude": {
"out": true "out": false // set this to true to hide the "out" folder with the compiled JS files
// "node_modules": true
}, },
"search.exclude": { "search.exclude": {
"out": true // set this to false to include "out" folder in search results "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,31 +1,20 @@
// See https://go.microsoft.com/fwlink/?LinkId=733558
// Available variables which can be used inside of strings. // for the documentation about the tasks.json format
// ${workspaceRoot}: 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 a custom npm script that compiles the extension.
{ {
"version": "0.2.0", "version": "2.0.0",
"tasks": [
// we want to run npm {
"command": "npm", "type": "npm",
"script": "watch",
// the command is a shell script "problemMatcher": "$tsc-watch",
"isShellCommand": true,
// show the output window only if unrecognized errors occur.
"showOutput": "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, "isBackground": true,
"presentation": {
// use the standard tsc in watch mode problem matcher to find compile problems in the output. "reveal": "never"
"problemMatcher": "$tsc-watch" },
"group": {
"kind": "build",
"isDefault": true
}
}
]
} }

9
code/.vscodeignore Normal file
View file

@ -0,0 +1,9 @@
.vscode/**
.vscode-test/**
out/test/**
out/**/*.map
src/**
.gitignore
tsconfig.json
vsc-extension-quickstart.md
tslint.json

30
code/package-lock.json generated
View file

@ -1,13 +1,19 @@
{ {
"name": "libsyntax-rust", "name": "rcf-lsp",
"version": "0.0.1", "version": "0.0.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"@types/mocha": {
"version": "2.2.48",
"resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-2.2.48.tgz",
"integrity": "sha512-nlK/iyETgafGli8Zh9zJVCTicvU3iajSkRwOh3Hhiva598CMqNJ4NcVCGMTGKpGpTYj/9R8RLzS9NAykSSCqGw==",
"dev": true
},
"@types/node": { "@types/node": {
"version": "7.0.69", "version": "8.10.28",
"resolved": "https://registry.npmjs.org/@types/node/-/node-7.0.69.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-8.10.28.tgz",
"integrity": "sha512-S5NC8HV6HnRipg8nC0j30TPl7ktXjRTKqgyINLNe8K/64UJUI8Lq0sRopXC0hProsV2F5ibj8IqPkl1xpGggrw==", "integrity": "sha512-iHsAzDg3OLH7JP+wipniUULHoDSWLgEDYOvsar6/mpAkTJd9/n23Ap8ikruMlvRTqMv/LXrflH9v/AfiEqaBGg==",
"dev": true "dev": true
}, },
"ajv": { "ajv": {
@ -284,9 +290,9 @@
} }
}, },
"commander": { "commander": {
"version": "2.17.1", "version": "2.11.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.17.1.tgz", "resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz",
"integrity": "sha512-wPMUt6FnH2yzG95SA6mzjQOEKUU3aLaDEmzs1ti+1E9h+CsrZghRlqEM/EJ4KscsQVG8uNN4uVreUeT8+drlgg==", "integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==",
"dev": true "dev": true
}, },
"concat-map": { "concat-map": {
@ -1478,12 +1484,6 @@
"supports-color": "4.4.0" "supports-color": "4.4.0"
}, },
"dependencies": { "dependencies": {
"commander": {
"version": "2.11.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz",
"integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==",
"dev": true
},
"glob": { "glob": {
"version": "7.1.2", "version": "7.1.2",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
@ -1658,7 +1658,7 @@
"integrity": "sha512-rgO9Zg5LLLkfJF9E6CCmXlSE4UVceloys8JrFqCcHloC3usd/kJCyPDwH2SOlzix2j3xaP9sUX3e8+kvkuleAA==", "integrity": "sha512-rgO9Zg5LLLkfJF9E6CCmXlSE4UVceloys8JrFqCcHloC3usd/kJCyPDwH2SOlzix2j3xaP9sUX3e8+kvkuleAA==",
"dev": true, "dev": true,
"requires": { "requires": {
"@types/node": "7.0.69" "@types/node": "8.10.28"
} }
}, },
"path-dirname": { "path-dirname": {
@ -2288,7 +2288,7 @@
"dev": true, "dev": true,
"requires": { "requires": {
"cheerio": "1.0.0-rc.2", "cheerio": "1.0.0-rc.2",
"commander": "2.17.1", "commander": "2.11.0",
"denodeify": "1.2.1", "denodeify": "1.2.1",
"glob": "7.1.3", "glob": "7.1.3",
"lodash": "4.17.10", "lodash": "4.17.10",

View file

@ -1,32 +1,38 @@
{ {
"name": "libsyntax-rust", "name": "rcf-lsp",
"displayName": "libsyntax-rust", "displayName": "rcf-lsp",
"description": "An experimental Rust plugin for VS Code based on libsyntax2", "description": "",
"license": "MIT",
"repository": "http://github.com/matklad/libsyntax2/",
"version": "0.0.1", "version": "0.0.1",
"publisher": "matklad", "publisher": "matklad",
"repository": {
"url": "https://github.com/matklad/libsyntax2/"
},
"categories": [
"Other"
],
"engines": { "engines": {
"vscode": "^1.26.0" "vscode": "^1.26.0"
}, },
"scripts": { "scripts": {
"vscode:prepublish": "tsc -p ./", "vscode:prepublish": "npm run compile",
"compile": "tsc -watch -p ./", "compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install" "postinstall": "node ./node_modules/vscode/bin/install"
}, },
"dependencies": { "dependencies": {
"vscode-languageclient": "^4.4.0" "vscode-languageclient": "^4.4.0"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^7.0.56", "typescript": "^2.6.1",
"typescript": "^2.9.1", "vscode": "^1.1.21",
"vsce": "^1.42.0", "vsce": "^1.42.0",
"vscode": "^1.1.18" "@types/node": "^8.10.25",
"@types/mocha": "^2.2.42"
}, },
"main": "./out/src/extension",
"activationEvents": [ "activationEvents": [
"onLanguage:rust" "onLanguage:rust"
], ],
"main": "./out/extension",
"contributes": { "contributes": {
"taskDefinitions": [ "taskDefinitions": [
{ {
@ -100,6 +106,11 @@
"command": "libsyntax-rust.joinLines", "command": "libsyntax-rust.joinLines",
"key": "ctrl+shift+j", "key": "ctrl+shift+j",
"when": "editorTextFocus && editorLangId == rust" "when": "editorTextFocus && editorLangId == rust"
},
{
"command": "libsyntax-rust.run",
"key": "ctrl+r",
"when": "editorTextFocus && editorLangId == rust"
} }
], ],
"problemMatchers": [ "problemMatchers": [

View file

@ -1,6 +1,7 @@
'use strict'; 'use strict';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import * as lc from 'vscode-languageclient' import * as lc from 'vscode-languageclient'
import { DH_UNABLE_TO_CHECK_GENERATOR } from 'constants';
let client: lc.LanguageClient; let client: lc.LanguageClient;
@ -12,10 +13,10 @@ let uris = {
export function activate(context: vscode.ExtensionContext) { export function activate(context: vscode.ExtensionContext) {
let textDocumentContentProvider = new TextDocumentContentProvider() let textDocumentContentProvider = new TextDocumentContentProvider()
let dispose = (disposable) => { let dispose = (disposable: vscode.Disposable) => {
context.subscriptions.push(disposable); context.subscriptions.push(disposable);
} }
let registerCommand = (name, f) => { let registerCommand = (name: string, f: any) => {
dispose(vscode.commands.registerCommand(name, f)) dispose(vscode.commands.registerCommand(name, f))
} }
@ -71,8 +72,8 @@ export function activate(context: vscode.ExtensionContext) {
let request: lc.TextDocumentIdentifier = { let request: lc.TextDocumentIdentifier = {
uri: editor.document.uri.toString() uri: editor.document.uri.toString()
} }
let response = await client.sendRequest<lc.TextDocumentIdentifier>("m/parentModule", request) let response = await client.sendRequest<lc.Location[]>("m/parentModule", request)
let loc: lc.Location = response[0] let loc = response[0]
if (loc == null) return if (loc == null) return
let uri = client.protocol2CodeConverter.asUri(loc.uri) let uri = client.protocol2CodeConverter.asUri(loc.uri)
let range = client.protocol2CodeConverter.asRange(loc.range) let range = client.protocol2CodeConverter.asRange(loc.range)
@ -82,19 +83,40 @@ export function activate(context: vscode.ExtensionContext) {
e.revealRange(range, vscode.TextEditorRevealType.InCenter) e.revealRange(range, vscode.TextEditorRevealType.InCenter)
}) })
registerCommand('libsyntax-rust.run', async (cmd: ProcessSpec) => { let prevRunnable: RunnableQuickPick | undefined = undefined
let task = createTask(cmd) registerCommand('libsyntax-rust.run', async () => {
await vscode.tasks.executeTask(task) let editor = vscode.window.activeTextEditor
if (editor == null || editor.document.languageId != "rust") return
let textDocument: lc.TextDocumentIdentifier = {
uri: editor.document.uri.toString()
}
let params: RunnablesParams = {
textDocument,
position: client.code2ProtocolConverter.asPosition(editor.selection.active)
}
let runnables = await client.sendRequest<Runnable[]>('m/runnables', params)
let items: RunnableQuickPick[] = []
if (prevRunnable) {
items.push(prevRunnable)
}
for (let r of runnables) {
items.push(new RunnableQuickPick(r))
}
let item = await vscode.window.showQuickPick(items)
if (item) {
item.detail = "last"
prevRunnable = item
let task = createTask(item.runnable)
return await vscode.tasks.executeTask(task)
}
}) })
registerCommand('libsyntax-rust.createFile', async (uri_: string) => { registerCommand('libsyntax-rust.createFile', async (uri_: string) => {
console.log(`uri: ${uri_}`)
let uri = vscode.Uri.parse(uri_) let uri = vscode.Uri.parse(uri_)
let edit = new vscode.WorkspaceEdit() let edit = new vscode.WorkspaceEdit()
edit.createFile(uri) edit.createFile(uri)
await vscode.workspace.applyEdit(edit) await vscode.workspace.applyEdit(edit)
let doc = await vscode.workspace.openTextDocument(uri) let doc = await vscode.workspace.openTextDocument(uri)
await vscode.window.showTextDocument(doc) await vscode.window.showTextDocument(doc)
console.log("Done")
}) })
dispose(vscode.workspace.registerTextDocumentContentProvider( dispose(vscode.workspace.registerTextDocumentContentProvider(
@ -113,13 +135,13 @@ export function activate(context: vscode.ExtensionContext) {
// We need to order this after LS updates, but there's no API for that. // We need to order this after LS updates, but there's no API for that.
// Hence, good old setTimeout. // Hence, good old setTimeout.
function afterLs(f) { function afterLs(f: () => any) {
setTimeout(f, 10) setTimeout(f, 10)
} }
export function deactivate(): Thenable<void> { export function deactivate(): Thenable<void> {
if (!client) { if (!client) {
return undefined; return Promise.resolve();
} }
return client.stop(); return client.stop();
} }
@ -148,7 +170,7 @@ function startServer() {
); );
client.onReady().then(() => { client.onReady().then(() => {
client.onNotification( client.onNotification(
new lc.NotificationType("m/publishDecorations"), "m/publishDecorations",
(params: PublishDecorationsParams) => { (params: PublishDecorationsParams) => {
let editor = vscode.window.visibleTextEditors.find( let editor = vscode.window.visibleTextEditors.find(
(editor) => editor.document.uri.toString() == params.uri (editor) => editor.document.uri.toString() == params.uri
@ -164,11 +186,11 @@ function startServer() {
new lc.RequestType<lc.Position, void, any, any>("m/moveCursor"), new lc.RequestType<lc.Position, void, any, any>("m/moveCursor"),
(params: lc.Position, token: lc.CancellationToken) => { (params: lc.Position, token: lc.CancellationToken) => {
let editor = vscode.window.activeTextEditor; let editor = vscode.window.activeTextEditor;
if (editor == null) return if (!editor) return
if (!editor.selection.isEmpty) return if (!editor.selection.isEmpty) return
let position = client.protocol2CodeConverter.asPosition(params) let position = client.protocol2CodeConverter.asPosition(params)
afterLs(() => { afterLs(() => {
editor.selection = new vscode.Selection(position, position) editor!.selection = new vscode.Selection(position, position)
}) })
} }
) )
@ -200,8 +222,8 @@ class TextDocumentContentProvider implements vscode.TextDocumentContentProvider
} }
const decorations = (() => { const decorations: { [index: string]: vscode.TextEditorDecorationType } = (() => {
const decor = (obj) => vscode.window.createTextEditorDecorationType({ color: obj }) const decor = (obj: any) => vscode.window.createTextEditorDecorationType({ color: obj })
return { return {
background: decor("#3F3F3F"), background: decor("#3F3F3F"),
error: vscode.window.createTextEditorDecorationType({ error: vscode.window.createTextEditorDecorationType({
@ -224,24 +246,24 @@ function setHighlights(
editor: vscode.TextEditor, editor: vscode.TextEditor,
highlihgs: Array<Decoration> highlihgs: Array<Decoration>
) { ) {
let byTag = {} let byTag: Map<string, vscode.Range[]> = new Map()
for (let tag in decorations) { for (let tag in decorations) {
byTag[tag] = [] byTag.set(tag, [])
} }
for (let d of highlihgs) { for (let d of highlihgs) {
if (!byTag[d.tag]) { if (!byTag.get(d.tag)) {
console.log(`unknown tag ${d.tag}`) console.log(`unknown tag ${d.tag}`)
continue continue
} }
byTag[d.tag].push( byTag.get(d.tag)!.push(
client.protocol2CodeConverter.asRange(d.range) client.protocol2CodeConverter.asRange(d.range)
) )
} }
for (let tag in byTag) { for (let tag of byTag.keys()) {
let dec = decorations[tag] let dec: vscode.TextEditorDecorationType = decorations[tag]
let ranges = byTag[tag] let ranges = byTag.get(tag)!
editor.setDecorations(dec, ranges) editor.setDecorations(dec, ranges)
} }
} }
@ -276,16 +298,35 @@ interface PublishDecorationsParams {
decorations: Decoration[], decorations: Decoration[],
} }
interface RunnablesParams {
textDocument: lc.TextDocumentIdentifier,
position?: lc.Position,
}
interface Runnable {
range: lc.Range;
label: string;
bin: string;
args: string[];
env: { [index: string]: string },
}
class RunnableQuickPick implements vscode.QuickPickItem {
label: string;
description?: string | undefined;
detail?: string | undefined;
picked?: boolean | undefined;
constructor(public runnable: Runnable) {
this.label = runnable.label
}
}
interface Decoration { interface Decoration {
range: lc.Range, range: lc.Range,
tag: string, tag: string,
} }
interface ProcessSpec {
bin: string;
args: string[];
env: { [key: string]: string };
}
interface CargoTaskDefinition extends vscode.TaskDefinition { interface CargoTaskDefinition extends vscode.TaskDefinition {
type: 'cargo'; type: 'cargo';
@ -295,8 +336,7 @@ interface CargoTaskDefinition extends vscode.TaskDefinition {
env?: { [key: string]: string }; env?: { [key: string]: string };
} }
function createTask(spec: Runnable): vscode.Task {
function createTask(spec: ProcessSpec): vscode.Task {
const TASK_SOURCE = 'Rust'; const TASK_SOURCE = 'Rust';
let definition: CargoTaskDefinition = { let definition: CargoTaskDefinition = {
type: 'cargo', type: 'cargo',
@ -313,7 +353,7 @@ function createTask(spec: ProcessSpec): vscode.Task {
}; };
let exec = new vscode.ShellExecution(execCmd, execOption); let exec = new vscode.ShellExecution(execCmd, execOption);
let f = vscode.workspace.workspaceFolders[0] let f = vscode.workspace.workspaceFolders![0]
let t = new vscode.Task(definition, f, definition.label, TASK_SOURCE, exec, ['$rustc']); let t = new vscode.Task(definition, f, definition.label, TASK_SOURCE, exec, ['$rustc']);
return t; return t;
} }

View file

@ -3,9 +3,15 @@
"module": "commonjs", "module": "commonjs",
"target": "es6", "target": "es6",
"outDir": "out", "outDir": "out",
"lib": [ "es6" ], "lib": [
"es6"
],
"sourceMap": true, "sourceMap": true,
"rootDir": "." "rootDir": "src",
"strict": true
}, },
"include": [ "src/*.ts" ], "exclude": [
"node_modules",
".vscode-test"
]
} }

View file

@ -135,48 +135,6 @@ pub fn handle_code_action(
res.push(cmd); res.push(cmd);
} }
} }
for runnable in libeditor::runnables(&file) {
if !contains_offset_nonstrict(runnable.range, offset) {
continue;
}
#[derive(Serialize)]
struct ProcessSpec {
bin: String,
args: Vec<String>,
env: HashMap<String, String>,
}
let spec = ProcessSpec {
bin: "cargo".to_string(),
args: match runnable.kind {
libeditor::RunnableKind::Test { name } => {
vec![
"test".to_string(),
"--".to_string(),
name,
"--nocapture".to_string(),
]
}
libeditor::RunnableKind::Bin => vec!["run".to_string()]
},
env: {
let mut m = HashMap::new();
m.insert(
"RUST_BACKTRACE".to_string(),
"short".to_string(),
);
m
}
};
let cmd = Command {
title: "Run ...".to_string(),
command: "libsyntax-rust.run".to_string(),
arguments: Some(vec![to_value(spec).unwrap()]),
};
res.push(cmd);
}
for (diag, quick_fix) in world.analysis().diagnostics(file_id)? { for (diag, quick_fix) in world.analysis().diagnostics(file_id)? {
let quick_fix = match quick_fix { let quick_fix = match quick_fix {

View file

@ -142,7 +142,7 @@ pub enum Runnables {}
impl Request for Runnables { impl Request for Runnables {
type Params = RunnablesParams; type Params = RunnablesParams;
type Result = Vec<Runnable>; type Result = Vec<Runnable>;
const METHOD: &'static str = "m/joinLines"; const METHOD: &'static str = "m/runnables";
} }
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]

View file

@ -204,7 +204,7 @@ cd code
execute!( execute!(
r" r"
cd code cd code
code --install-extension ./libsyntax-rust-0.0.1.vsix code --install-extension ./rcf-lsp-0.0.1.vsix
" "
)?; )?;
Ok(()) Ok(())