mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
reorganize
This commit is contained in:
parent
9863b9161d
commit
f99551f46b
16 changed files with 159 additions and 3814 deletions
1
code/.gitignore
vendored
1
code/.gitignore
vendored
|
@ -4,3 +4,4 @@ artifacts.json
|
||||||
*.vsix
|
*.vsix
|
||||||
out/*
|
out/*
|
||||||
node_modules/*
|
node_modules/*
|
||||||
|
log/*
|
||||||
|
|
278
code/common.ts
278
code/common.ts
|
@ -1,278 +0,0 @@
|
||||||
import * as vscode from 'vscode'
|
|
||||||
import { log } from 'util'
|
|
||||||
|
|
||||||
export function createPlugin(
|
|
||||||
backend,
|
|
||||||
fileExtension: string,
|
|
||||||
disposables: vscode.Disposable[],
|
|
||||||
doHighlighting: boolean = false,
|
|
||||||
diganosticCollection: vscode.DiagnosticCollection | null = null
|
|
||||||
) {
|
|
||||||
let uris = {
|
|
||||||
syntaxTree: vscode.Uri.parse(`fall-${fileExtension}://syntaxtree`),
|
|
||||||
metrics: vscode.Uri.parse(`fall-${fileExtension}://metrics`)
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateActiveEditor() {
|
|
||||||
let editor = vscode.window.activeTextEditor
|
|
||||||
if (editor == null) return
|
|
||||||
let file = currentFile()
|
|
||||||
if (file == null) return
|
|
||||||
if (doHighlighting) {
|
|
||||||
setHighlights(editor, file.highlight())
|
|
||||||
}
|
|
||||||
if (diganosticCollection != null) {
|
|
||||||
diganosticCollection.clear()
|
|
||||||
diganosticCollection.set(
|
|
||||||
editor.document.uri,
|
|
||||||
file.diagnostics()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function currentFile(): EditorFile | null {
|
|
||||||
let editor = vscode.window.activeTextEditor
|
|
||||||
if (editor == null) return
|
|
||||||
let doc = editor.document
|
|
||||||
return getFile(doc)
|
|
||||||
}
|
|
||||||
|
|
||||||
vscode.window.onDidChangeActiveTextEditor(updateActiveEditor)
|
|
||||||
let cmd = vscode.commands.registerCommand(`fall-${fileExtension}.applyContextAction`, (range, id) => {
|
|
||||||
let file = currentFile()
|
|
||||||
if (file == null) return
|
|
||||||
return file.applyContextAction(range, id)
|
|
||||||
})
|
|
||||||
disposables.push(cmd)
|
|
||||||
|
|
||||||
return {
|
|
||||||
getFile: getFile,
|
|
||||||
showSyntaxTree: () => {
|
|
||||||
let file = currentFile()
|
|
||||||
if (file == null) return
|
|
||||||
return openDoc(uris.syntaxTree)
|
|
||||||
},
|
|
||||||
metrics: () => {
|
|
||||||
let file = currentFile()
|
|
||||||
if (file == null) return
|
|
||||||
return openDoc(uris.metrics)
|
|
||||||
},
|
|
||||||
extendSelection: () => {
|
|
||||||
let editor = vscode.window.activeTextEditor
|
|
||||||
let file = currentFile()
|
|
||||||
if (editor == null || file == null) return
|
|
||||||
editor.selections = editor.selections.map((s) => {
|
|
||||||
let range = file.extendSelection(s)
|
|
||||||
return new vscode.Selection(range.start, range.end)
|
|
||||||
})
|
|
||||||
},
|
|
||||||
documentSymbolsProvider: new DocumentSymbolProvider(getFile),
|
|
||||||
documentFormattingEditProvider: new DocumentFormattingEditProvider(getFile),
|
|
||||||
codeActionProvider: new CodeActionProvider(getFile, fileExtension)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export interface FileStructureNode {
|
|
||||||
name: string
|
|
||||||
range: [number, number]
|
|
||||||
children: [FileStructureNode]
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FallDiagnostic {
|
|
||||||
range: [number, number]
|
|
||||||
severity: string
|
|
||||||
message: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export class EditorFile {
|
|
||||||
backend;
|
|
||||||
imp;
|
|
||||||
doc: vscode.TextDocument;
|
|
||||||
|
|
||||||
constructor(backend, imp, doc: vscode.TextDocument) {
|
|
||||||
this.backend = backend
|
|
||||||
this.imp = imp
|
|
||||||
this.doc = doc
|
|
||||||
}
|
|
||||||
|
|
||||||
metrics(): string { return this.call("metrics") }
|
|
||||||
syntaxTree(): string { return this.call("syntaxTree") }
|
|
||||||
extendSelection(range_: vscode.Range): vscode.Range | null {
|
|
||||||
let range = fromVsRange(this.doc, range_)
|
|
||||||
let exp = this.call("extendSelection", range)
|
|
||||||
if (exp == null) return null
|
|
||||||
return toVsRange(this.doc, exp)
|
|
||||||
}
|
|
||||||
|
|
||||||
structure(): Array<FileStructureNode> { return this.call("structure") }
|
|
||||||
reformat(): Array<vscode.TextEdit> {
|
|
||||||
let edits = this.call("reformat")
|
|
||||||
return toVsEdits(this.doc, edits)
|
|
||||||
}
|
|
||||||
|
|
||||||
highlight(): Array<[[number, number], string]> { return this.call("highlight") }
|
|
||||||
diagnostics(): Array<vscode.Diagnostic> {
|
|
||||||
return this.call("diagnostics").map((d) => {
|
|
||||||
let range = toVsRange(this.doc, d.range)
|
|
||||||
let severity = d.severity == "Error"
|
|
||||||
? vscode.DiagnosticSeverity.Error
|
|
||||||
: vscode.DiagnosticSeverity.Warning
|
|
||||||
|
|
||||||
return new vscode.Diagnostic(range, d.message, severity)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
contextActions(range_: vscode.Range): Array<string> {
|
|
||||||
let range = fromVsRange(this.doc, range_)
|
|
||||||
let result = this.call("contextActions", range)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
applyContextAction(range_: vscode.Range, id: string) {
|
|
||||||
let range = fromVsRange(this.doc, range_)
|
|
||||||
let edits = this.call("applyContextAction", range, id)
|
|
||||||
let editor = vscode.window.activeTextEditor
|
|
||||||
return editor.edit((builder) => {
|
|
||||||
for (let op of edits) {
|
|
||||||
builder.replace(toVsRange(this.doc, op.delete), op.insert)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
call(method: string, ...args) {
|
|
||||||
let result = this.backend[method](this.imp, ...args)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function documentToFile(backend, fileExtension: string, disposables: vscode.Disposable[], onChange) {
|
|
||||||
let docs = {}
|
|
||||||
function update(doc: vscode.TextDocument, file) {
|
|
||||||
let key = doc.uri.toString()
|
|
||||||
if (file == null) {
|
|
||||||
delete docs[key]
|
|
||||||
} else {
|
|
||||||
docs[key] = file
|
|
||||||
}
|
|
||||||
onChange(doc)
|
|
||||||
}
|
|
||||||
function get(doc: vscode.TextDocument) {
|
|
||||||
return docs[doc.uri.toString()]
|
|
||||||
}
|
|
||||||
|
|
||||||
function isKnownDoc(doc: vscode.TextDocument) {
|
|
||||||
return doc.fileName.endsWith(`.${fileExtension}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
vscode.workspace.onDidChangeTextDocument((event: vscode.TextDocumentChangeEvent) => {
|
|
||||||
let doc = event.document
|
|
||||||
if (!isKnownDoc(event.document)) return
|
|
||||||
let tree = get(doc)
|
|
||||||
if (event.contentChanges.length == 1 && tree) {
|
|
||||||
let edits = event.contentChanges.map((change) => {
|
|
||||||
let start = doc.offsetAt(change.range.start)
|
|
||||||
return {
|
|
||||||
"delete": [start, start + change.rangeLength],
|
|
||||||
"insert": change.text
|
|
||||||
}
|
|
||||||
})
|
|
||||||
update(doc, backend.edit(tree, edits))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
update(doc, null)
|
|
||||||
}, null, disposables)
|
|
||||||
|
|
||||||
vscode.workspace.onDidOpenTextDocument((doc: vscode.TextDocument) => {
|
|
||||||
if (!isKnownDoc(doc)) return
|
|
||||||
update(doc, backend.parse(doc.getText()))
|
|
||||||
}, null, disposables)
|
|
||||||
|
|
||||||
vscode.workspace.onDidCloseTextDocument((doc: vscode.TextDocument) => {
|
|
||||||
update(doc, null)
|
|
||||||
}, null, disposables)
|
|
||||||
|
|
||||||
return (doc: vscode.TextDocument) => {
|
|
||||||
if (!isKnownDoc(doc)) return null
|
|
||||||
|
|
||||||
if (!get(doc)) {
|
|
||||||
update(doc, backend.parse(doc.getText()))
|
|
||||||
}
|
|
||||||
let imp = get(doc)
|
|
||||||
return new EditorFile(backend, imp, doc)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class DocumentSymbolProvider implements vscode.DocumentSymbolProvider {
|
|
||||||
getFile: (doc: vscode.TextDocument) => EditorFile | null;
|
|
||||||
constructor(getFile) {
|
|
||||||
this.getFile = getFile
|
|
||||||
}
|
|
||||||
|
|
||||||
provideDocumentSymbols(document: vscode.TextDocument, token: vscode.CancellationToken) {
|
|
||||||
let file = this.getFile(document)
|
|
||||||
if (file == null) return null
|
|
||||||
return file.structure().map((node) => {
|
|
||||||
return new vscode.SymbolInformation(
|
|
||||||
node.name,
|
|
||||||
vscode.SymbolKind.Function,
|
|
||||||
toVsRange(document, node.range),
|
|
||||||
null,
|
|
||||||
null
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class DocumentFormattingEditProvider implements vscode.DocumentFormattingEditProvider {
|
|
||||||
getFile: (doc: vscode.TextDocument) => EditorFile | null;
|
|
||||||
constructor(getFile) { this.getFile = getFile }
|
|
||||||
|
|
||||||
provideDocumentFormattingEdits(
|
|
||||||
document: vscode.TextDocument,
|
|
||||||
options: vscode.FormattingOptions,
|
|
||||||
token: vscode.CancellationToken
|
|
||||||
): vscode.TextEdit[] {
|
|
||||||
let file = this.getFile(document)
|
|
||||||
if (file == null) return []
|
|
||||||
return file.reformat()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class CodeActionProvider implements vscode.CodeActionProvider {
|
|
||||||
fileExtension: string
|
|
||||||
getFile: (doc: vscode.TextDocument) => EditorFile | null;
|
|
||||||
constructor(getFile, fileExtension) {
|
|
||||||
this.getFile = getFile
|
|
||||||
this.fileExtension = fileExtension
|
|
||||||
}
|
|
||||||
|
|
||||||
provideCodeActions(
|
|
||||||
document: vscode.TextDocument,
|
|
||||||
range: vscode.Range,
|
|
||||||
context: vscode.CodeActionContext,
|
|
||||||
token: vscode.CancellationToken
|
|
||||||
): vscode.Command[] {
|
|
||||||
let file = this.getFile(document)
|
|
||||||
if (file == null) return
|
|
||||||
let actions = file.contextActions(range)
|
|
||||||
return actions.map((id) => {
|
|
||||||
return {
|
|
||||||
title: id,
|
|
||||||
command: `fall-${this.fileExtension}.applyContextAction`,
|
|
||||||
arguments: [range, id]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export function toVsEdits(doc: vscode.TextDocument, edits): Array<vscode.TextEdit> {
|
|
||||||
return edits.map((op) => vscode.TextEdit.replace(toVsRange(doc, op.delete), op.insert))
|
|
||||||
}
|
|
||||||
|
|
||||||
async function openDoc(uri: vscode.Uri) {
|
|
||||||
let document = await vscode.workspace.openTextDocument(uri)
|
|
||||||
vscode.window.showTextDocument(document, vscode.ViewColumn.Two, true)
|
|
||||||
}
|
|
860
code/package-lock.json
generated
860
code/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -1,56 +1,48 @@
|
||||||
{
|
{
|
||||||
"name": "libsyntax-rust",
|
"name": "libsyntax-rust",
|
||||||
"displayName": "libsyntax-rust",
|
"displayName": "libsyntax-rust",
|
||||||
"description": "An experimental Rust plugin for VS Code based on libsyntax2",
|
"description": "An experimental Rust plugin for VS Code based on libsyntax2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": "http://github.com/matklad/libsyntax2/",
|
"repository": "http://github.com/matklad/libsyntax2/",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"publisher": "matklad",
|
"publisher": "matklad",
|
||||||
"engines": {
|
"engines": {
|
||||||
"vscode": "^1.18.0"
|
"vscode": "^1.25.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"scripts": {
|
||||||
"@types/node": "^6.0.112",
|
"compile": "tsc -p ./",
|
||||||
"neon-cli": "^0.2.0",
|
"postinstall": "node ./node_modules/vscode/bin/install"
|
||||||
"typescript": "^2.9.1",
|
},
|
||||||
"vsce": "^1.42.0",
|
"dependencies": {
|
||||||
"vscode": "^1.1.18"
|
"vscode-languageclient": "^4.3.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"devDependencies": {
|
||||||
"vscode:prepublish": "tsc -p ./",
|
"@types/node": "^7.0.56",
|
||||||
"compile": "tsc -watch -p ./",
|
"typescript": "^2.9.1",
|
||||||
"install": "neon build",
|
"vsce": "^1.42.0",
|
||||||
"postinstall": "node ./node_modules/vscode/bin/install"
|
"vscode": "^1.1.18"
|
||||||
},
|
},
|
||||||
"main": "./out/src/main",
|
"main": "./out/src/extension",
|
||||||
"contributes": {
|
"activationEvents": [
|
||||||
"languages": [
|
"onLanguage:rust"
|
||||||
{
|
],
|
||||||
"id": "rust",
|
"contributes": {
|
||||||
"extensions": [
|
"commands": [
|
||||||
".rs"
|
{
|
||||||
]
|
"command": "libsyntax-rust.syntaxTree",
|
||||||
}
|
"title": "Show Rust syntax tree"
|
||||||
],
|
},
|
||||||
"commands": [
|
{
|
||||||
{
|
"command": "libsyntax-rust.extendSelection",
|
||||||
"command": "libsyntax-rust.syntaxTree",
|
"title": "Rust Extend Selection"
|
||||||
"title": "Show Rust syntax tree"
|
}
|
||||||
},
|
],
|
||||||
{
|
"keybindings": [
|
||||||
"command": "libsyntax-rust.extendSelection",
|
{
|
||||||
"title": "Rust Extend Selection"
|
"command": "libsyntax-rust.extendSelection",
|
||||||
}
|
"key": "ctrl+w",
|
||||||
],
|
"when": "editorTextFocus && editorLangId == rust"
|
||||||
"keybindings": [
|
}
|
||||||
{
|
|
||||||
"command": "libsyntax-rust.extendSelection",
|
|
||||||
"key": "ctrl+w",
|
|
||||||
"when": "editorTextFocus && editorLangId == rust"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"activationEvents": [
|
|
||||||
"onLanguage:rust"
|
|
||||||
]
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,8 +63,8 @@ export function deactivate(): Thenable<void> {
|
||||||
|
|
||||||
function startServer() {
|
function startServer() {
|
||||||
let run: lc.Executable = {
|
let run: lc.Executable = {
|
||||||
command: "cargo",
|
command: "m",
|
||||||
args: ["run", "--package", "m"],
|
// args: ["run", "--package", "m"],
|
||||||
options: { cwd: "." }
|
options: { cwd: "." }
|
||||||
}
|
}
|
||||||
let serverOptions: lc.ServerOptions = {
|
let serverOptions: lc.ServerOptions = {
|
||||||
|
@ -86,11 +86,6 @@ function startServer() {
|
||||||
client.onNotification(
|
client.onNotification(
|
||||||
new lc.NotificationType("m/publishDecorations"),
|
new lc.NotificationType("m/publishDecorations"),
|
||||||
(params: PublishDecorationsParams) => {
|
(params: PublishDecorationsParams) => {
|
||||||
console.log("A");
|
|
||||||
console.log(params.uri);
|
|
||||||
console.log(vscode.window.activeTextEditor.document.uri.toString());
|
|
||||||
console.log("B");
|
|
||||||
|
|
||||||
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
|
||||||
)
|
)
|
208
code/src/main.ts
208
code/src/main.ts
|
@ -1,208 +0,0 @@
|
||||||
'use strict'
|
|
||||||
import * as vscode from 'vscode'
|
|
||||||
|
|
||||||
const backend = require("../../native")
|
|
||||||
|
|
||||||
let docToSyntax;
|
|
||||||
|
|
||||||
let uris = {
|
|
||||||
syntaxTree: vscode.Uri.parse('libsyntax-rust://syntaxtree')
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export function activate(context: vscode.ExtensionContext) {
|
|
||||||
let textDocumentContentProvider = new TextDocumentContentProvider()
|
|
||||||
let dispose = (disposable) => {
|
|
||||||
context.subscriptions.push(disposable);
|
|
||||||
}
|
|
||||||
|
|
||||||
let registerCommand = (name, f) => {
|
|
||||||
dispose(vscode.commands.registerCommand(name, f))
|
|
||||||
}
|
|
||||||
|
|
||||||
docToSyntax = documentToFile(context.subscriptions, () => {
|
|
||||||
let emitter = textDocumentContentProvider.eventEmitter
|
|
||||||
emitter.fire(uris.syntaxTree)
|
|
||||||
let syntax = activeSyntax()
|
|
||||||
setHighlights(vscode.window.activeTextEditor, syntax.highlight())
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
dispose(vscode.workspace.registerTextDocumentContentProvider(
|
|
||||||
'libsyntax-rust',
|
|
||||||
textDocumentContentProvider
|
|
||||||
))
|
|
||||||
|
|
||||||
registerCommand('libsyntax-rust.syntaxTree', () => openDoc(uris.syntaxTree))
|
|
||||||
registerCommand('libsyntax-rust.extendSelection', () => {
|
|
||||||
let editor = vscode.window.activeTextEditor
|
|
||||||
let file = activeSyntax()
|
|
||||||
if (editor == null || file == null) return
|
|
||||||
editor.selections = editor.selections.map((s) => {
|
|
||||||
let range = file.extendSelection(s)
|
|
||||||
if (range == null) return null
|
|
||||||
return new vscode.Selection(range.start, range.end)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export function deactivate() { }
|
|
||||||
|
|
||||||
export class Syntax {
|
|
||||||
imp;
|
|
||||||
doc: vscode.TextDocument;
|
|
||||||
|
|
||||||
constructor(imp, doc: vscode.TextDocument) {
|
|
||||||
this.imp = imp
|
|
||||||
this.doc = doc
|
|
||||||
}
|
|
||||||
|
|
||||||
syntaxTree(): string { return this.imp.syntaxTree() }
|
|
||||||
highlight(): Array<[number, number, string]> { return this.imp.highlight() }
|
|
||||||
extendSelection(range: vscode.Range): vscode.Range {
|
|
||||||
let range_ = fromVsRange(this.doc, range);
|
|
||||||
let extRange = this.imp.extendSelection(range_[0], range_[1]);
|
|
||||||
return toVsRange(this.doc, extRange);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function activeDoc() {
|
|
||||||
return vscode.window.activeTextEditor.document
|
|
||||||
}
|
|
||||||
|
|
||||||
function activeSyntax(): Syntax {
|
|
||||||
let doc = activeDoc()
|
|
||||||
if (doc == null) return null
|
|
||||||
return docToSyntax(doc)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function openDoc(uri: vscode.Uri) {
|
|
||||||
let document = await vscode.workspace.openTextDocument(uri)
|
|
||||||
return vscode.window.showTextDocument(document, vscode.ViewColumn.Two, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
function documentToFile(disposables: vscode.Disposable[], onChange) {
|
|
||||||
let docs = {}
|
|
||||||
function update(doc: vscode.TextDocument, file) {
|
|
||||||
let key = doc.uri.toString()
|
|
||||||
if (file == null) {
|
|
||||||
delete docs[key]
|
|
||||||
} else {
|
|
||||||
docs[key] = file
|
|
||||||
}
|
|
||||||
onChange(doc)
|
|
||||||
}
|
|
||||||
function get(doc: vscode.TextDocument) {
|
|
||||||
return docs[doc.uri.toString()]
|
|
||||||
}
|
|
||||||
|
|
||||||
function isKnownDoc(doc: vscode.TextDocument) {
|
|
||||||
return doc.fileName.endsWith('.rs')
|
|
||||||
}
|
|
||||||
|
|
||||||
function createFile(text: String) {
|
|
||||||
console.time("parsing")
|
|
||||||
let res = new backend.RustFile(text);
|
|
||||||
console.timeEnd("parsing")
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
vscode.workspace.onDidChangeTextDocument((event: vscode.TextDocumentChangeEvent) => {
|
|
||||||
let doc = event.document
|
|
||||||
if (!isKnownDoc(event.document)) return
|
|
||||||
update(doc, null)
|
|
||||||
}, null, disposables)
|
|
||||||
|
|
||||||
vscode.workspace.onDidOpenTextDocument((doc: vscode.TextDocument) => {
|
|
||||||
if (!isKnownDoc(doc)) return
|
|
||||||
update(doc, createFile(doc.getText()))
|
|
||||||
}, null, disposables)
|
|
||||||
|
|
||||||
vscode.workspace.onDidCloseTextDocument((doc: vscode.TextDocument) => {
|
|
||||||
update(doc, null)
|
|
||||||
}, null, disposables)
|
|
||||||
|
|
||||||
return (doc: vscode.TextDocument) => {
|
|
||||||
if (!isKnownDoc(doc)) return null
|
|
||||||
|
|
||||||
if (!get(doc)) {
|
|
||||||
update(doc, createFile(doc.getText()))
|
|
||||||
}
|
|
||||||
let imp = get(doc)
|
|
||||||
return new Syntax(imp, doc)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class TextDocumentContentProvider implements vscode.TextDocumentContentProvider {
|
|
||||||
public eventEmitter = new vscode.EventEmitter<vscode.Uri>()
|
|
||||||
public syntaxTree: string = "Not available"
|
|
||||||
|
|
||||||
public provideTextDocumentContent(uri: vscode.Uri): vscode.ProviderResult<string> {
|
|
||||||
let syntax = activeSyntax()
|
|
||||||
if (syntax == null) return
|
|
||||||
if (uri.toString() == uris.syntaxTree.toString()) {
|
|
||||||
return syntax.syntaxTree()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
get onDidChange(): vscode.Event<vscode.Uri> {
|
|
||||||
return this.eventEmitter.event
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const decorations = (() => {
|
|
||||||
const decor = (obj) => vscode.window.createTextEditorDecorationType({ color: obj })
|
|
||||||
return {
|
|
||||||
background: decor("#3F3F3F"),
|
|
||||||
error: vscode.window.createTextEditorDecorationType({
|
|
||||||
borderColor: "red",
|
|
||||||
borderStyle: "none none dashed none",
|
|
||||||
}),
|
|
||||||
comment: decor("#7F9F7F"),
|
|
||||||
string: decor("#CC9393"),
|
|
||||||
keyword: decor("#F0DFAF"),
|
|
||||||
function: decor("#93E0E3"),
|
|
||||||
parameter: decor("#94BFF3"),
|
|
||||||
builtin: decor("#DD6718"),
|
|
||||||
text: decor("#DCDCCC"),
|
|
||||||
attribute: decor("#BFEBBF"),
|
|
||||||
literal: decor("#DFAF8F"),
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
|
|
||||||
function setHighlights(
|
|
||||||
editor: vscode.TextEditor,
|
|
||||||
highlihgs: Array<[number, number, string]>
|
|
||||||
) {
|
|
||||||
let byTag = {}
|
|
||||||
for (let tag in decorations) {
|
|
||||||
byTag[tag] = []
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let [start, end, tag] of highlihgs) {
|
|
||||||
if (!byTag[tag]) {
|
|
||||||
console.log(`unknown tag ${tag}`)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
let range = toVsRange(editor.document, [start, end])
|
|
||||||
byTag[tag].push(range)
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let tag in byTag) {
|
|
||||||
let dec = decorations[tag]
|
|
||||||
let ranges = byTag[tag]
|
|
||||||
editor.setDecorations(dec, ranges)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function toVsRange(doc: vscode.TextDocument, range: [number, number]): vscode.Range {
|
|
||||||
return new vscode.Range(
|
|
||||||
doc.positionAt(range[0]),
|
|
||||||
doc.positionAt(range[1]),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function fromVsRange(doc: vscode.TextDocument, range: vscode.Range): [number, number] {
|
|
||||||
return [doc.offsetAt(range.start), doc.offsetAt(range.end)]
|
|
||||||
}
|
|
|
@ -7,5 +7,6 @@
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"rootDir": "."
|
"rootDir": "."
|
||||||
},
|
},
|
||||||
"include": [ "src/*.ts" ]
|
"include": [ "src" ],
|
||||||
|
"exclude": [ "node_modules" ]
|
||||||
}
|
}
|
7
codeless/.gitignore
vendored
7
codeless/.gitignore
vendored
|
@ -1,7 +0,0 @@
|
||||||
target
|
|
||||||
index.node
|
|
||||||
artifacts.json
|
|
||||||
*.vsix
|
|
||||||
out/*
|
|
||||||
node_modules/*
|
|
||||||
log/*
|
|
|
@ -1,4 +0,0 @@
|
||||||
runtime = electron
|
|
||||||
target = 1.7.9
|
|
||||||
target_arch = x64
|
|
||||||
disturl = https://atom.io/download/atom-shell
|
|
19
codeless/.vscode/launch.json
vendored
19
codeless/.vscode/launch.json
vendored
|
@ -1,19 +0,0 @@
|
||||||
{
|
|
||||||
// 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": "Launch Extension",
|
|
||||||
"type": "extensionHost",
|
|
||||||
"request": "launch",
|
|
||||||
"runtimeExecutable": "${execPath}",
|
|
||||||
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
|
|
||||||
"stopOnEntry": false,
|
|
||||||
"sourceMaps": true,
|
|
||||||
"outFiles": [ "${workspaceRoot}/out/src/**/*.js" ],
|
|
||||||
"preLaunchTask": "npm"
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
10
codeless/.vscode/settings.json
vendored
10
codeless/.vscode/settings.json
vendored
|
@ -1,10 +0,0 @@
|
||||||
// Place your settings in this file to overwrite default and user settings.
|
|
||||||
{
|
|
||||||
"files.exclude": {
|
|
||||||
"out": true,
|
|
||||||
"node_modules": true
|
|
||||||
},
|
|
||||||
"search.exclude": {
|
|
||||||
"out": true // set this to false to include "out" folder in search results
|
|
||||||
}
|
|
||||||
}
|
|
31
codeless/.vscode/tasks.json
vendored
31
codeless/.vscode/tasks.json
vendored
|
@ -1,31 +0,0 @@
|
||||||
|
|
||||||
// Available variables which can be used inside of strings.
|
|
||||||
// ${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",
|
|
||||||
|
|
||||||
// we want to run npm
|
|
||||||
"command": "npm",
|
|
||||||
|
|
||||||
// the command is a shell script
|
|
||||||
"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", "--loglevel", "silent"],
|
|
||||||
|
|
||||||
// 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"
|
|
||||||
}
|
|
2381
codeless/package-lock.json
generated
2381
codeless/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -1,48 +0,0 @@
|
||||||
{
|
|
||||||
"name": "libsyntax-rust",
|
|
||||||
"displayName": "libsyntax-rust",
|
|
||||||
"description": "An experimental Rust plugin for VS Code based on libsyntax2",
|
|
||||||
"license": "MIT",
|
|
||||||
"repository": "http://github.com/matklad/libsyntax2/",
|
|
||||||
"version": "0.0.1",
|
|
||||||
"publisher": "matklad",
|
|
||||||
"engines": {
|
|
||||||
"vscode": "^1.25.0"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"compile": "tsc -p ./",
|
|
||||||
"postinstall": "node ./node_modules/vscode/bin/install"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"vscode-languageclient": "^4.3.0"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/node": "^7.0.56",
|
|
||||||
"typescript": "^2.9.1",
|
|
||||||
"vsce": "^1.42.0",
|
|
||||||
"vscode": "^1.1.18"
|
|
||||||
},
|
|
||||||
"main": "./out/src/extension",
|
|
||||||
"activationEvents": [
|
|
||||||
"onLanguage:rust"
|
|
||||||
],
|
|
||||||
"contributes": {
|
|
||||||
"commands": [
|
|
||||||
{
|
|
||||||
"command": "libsyntax-rust.syntaxTree",
|
|
||||||
"title": "Show Rust syntax tree"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"command": "libsyntax-rust.extendSelection",
|
|
||||||
"title": "Rust Extend Selection"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"keybindings": [
|
|
||||||
{
|
|
||||||
"command": "libsyntax-rust.extendSelection",
|
|
||||||
"key": "ctrl+w",
|
|
||||||
"when": "editorTextFocus && editorLangId == rust"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,12 +0,0 @@
|
||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"module": "commonjs",
|
|
||||||
"target": "es6",
|
|
||||||
"outDir": "out",
|
|
||||||
"lib": [ "es6" ],
|
|
||||||
"sourceMap": true,
|
|
||||||
"rootDir": "."
|
|
||||||
},
|
|
||||||
"include": [ "src" ],
|
|
||||||
"exclude": [ "node_modules" ]
|
|
||||||
}
|
|
|
@ -39,7 +39,7 @@ use ::{
|
||||||
pub type Result<T> = ::std::result::Result<T, ::failure::Error>;
|
pub type Result<T> = ::std::result::Result<T, ::failure::Error>;
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
Logger::with_env_or_str("m=trace, libanalysis=trace")
|
Logger::with_env()
|
||||||
.log_to_file()
|
.log_to_file()
|
||||||
.directory("log")
|
.directory("log")
|
||||||
.start()?;
|
.start()?;
|
||||||
|
|
Loading…
Reference in a new issue