forked from OSchip/llvm-project
[mlir] Add a vscode language extension for MLIR
This utilizes the mlir-lsp server to provide language services for MLIR files opened in vscode. The extension currently supports syntax highlighting, as well as tracking definitions/uses/source locations for SSA values and blocks. Differential Revision: https://reviews.llvm.org/D100607
This commit is contained in:
parent
751c14fc42
commit
b810e3a552
|
@ -0,0 +1,7 @@
|
|||
out
|
||||
node_modules
|
||||
.vscode-test
|
||||
*.vsix
|
||||
grammar.json
|
||||
|
||||
!.vscode
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
// 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": [
|
||||
{
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"name": "Run Extension",
|
||||
"runtimeExecutable": "${execPath}",
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceRoot}"
|
||||
],
|
||||
"outFiles": [
|
||||
"${workspaceRoot}/out/**/*.js"
|
||||
],
|
||||
"preLaunchTask": {
|
||||
"type": "npm",
|
||||
"script": "watch"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "compile",
|
||||
"group": "build",
|
||||
"presentation": {
|
||||
"panel": "dedicated",
|
||||
"reveal": "never"
|
||||
},
|
||||
"problemMatcher": [
|
||||
"$tsc"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "watch",
|
||||
"isBackground": true,
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"presentation": {
|
||||
"panel": "dedicated",
|
||||
"reveal": "never"
|
||||
},
|
||||
"problemMatcher": [
|
||||
"$tsc-watch"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
.vscode/**
|
||||
.vscode-test/**
|
||||
.gitignore
|
||||
vsc-extension-quickstart.md
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"comments": {
|
||||
"lineComment": "//"
|
||||
},
|
||||
"brackets": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["(", ")"]
|
||||
],
|
||||
"autoClosingPairs": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["(", ")"],
|
||||
["\"", "\""]
|
||||
],
|
||||
"surroundingPairs": [
|
||||
["{", "}"],
|
||||
["[", "]"],
|
||||
["(", ")"],
|
||||
["\"", "\""]
|
||||
]
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,70 @@
|
|||
{
|
||||
"name": "mlir",
|
||||
"displayName": "MLIR",
|
||||
"description": "MLIR Language Extension",
|
||||
"version": "0.0.1",
|
||||
"publisher": "llvm-vs-code-extensions",
|
||||
"repository": "https://github.com/llvm/llvm-project/",
|
||||
"engines": {
|
||||
"vscode": "^1.52.0"
|
||||
},
|
||||
"categories": [
|
||||
"Programming Languages"
|
||||
],
|
||||
"activationEvents": [
|
||||
"onLanguage:mlir"
|
||||
],
|
||||
"main": "./out/extension",
|
||||
"contributes": {
|
||||
"languages": [
|
||||
{
|
||||
"id": "mlir",
|
||||
"aliases": [
|
||||
"MLIR",
|
||||
"mlir"
|
||||
],
|
||||
"extensions": [
|
||||
".mlir"
|
||||
],
|
||||
"configuration": "./language-configuration.json"
|
||||
}
|
||||
],
|
||||
"grammars": [
|
||||
{
|
||||
"language": "mlir",
|
||||
"scopeName": "source.mlir",
|
||||
"path": "./grammar.json"
|
||||
}
|
||||
],
|
||||
"configuration": {
|
||||
"type": "object",
|
||||
"title": "MLIR",
|
||||
"properties": {
|
||||
"mlir.server_path": {
|
||||
"scope": "resource",
|
||||
"type": "string",
|
||||
"description": "The file path of the mlir-lsp-server executable."
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "tsc -p ./",
|
||||
"compile": "tsc -watch -p ./",
|
||||
"format": "clang-format -i --glob=\"{src,test}/*.ts\"",
|
||||
"test": "tsc -p ./ && node ./out/test/index.js",
|
||||
"package": "vsce package"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/mocha": "^5.2.0",
|
||||
"@types/node": "^8.0.0",
|
||||
"@types/vscode": "1.52.*",
|
||||
"clang-format": "1.4.0",
|
||||
"tslint": "^5.16.0",
|
||||
"typescript": "^3.5.1",
|
||||
"vsce": "^1.75.0",
|
||||
"vscode-languageclient": "^5.2.1",
|
||||
"vscode-test": "^1.3.0"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
import * as vscode from 'vscode';
|
||||
import * as vscodelc from 'vscode-languageclient';
|
||||
|
||||
let client: vscodelc.LanguageClient;
|
||||
|
||||
/**
|
||||
* This method is called when the extension is activated. The extension is
|
||||
* activated the very first time a command is executed.
|
||||
*/
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
// Get the path of the mlir-lsp-server that is used to provide language
|
||||
// functionality.
|
||||
const config = vscode.workspace.getConfiguration('mlir');
|
||||
const userDefinedServerPath = config.get<string>('server_path');
|
||||
const serverPath = (userDefinedServerPath === '') ? 'mlir-lsp-server'
|
||||
: userDefinedServerPath;
|
||||
|
||||
// Configure the server options.
|
||||
const serverOptions: vscodelc.ServerOptions = {
|
||||
run : {
|
||||
command : serverPath,
|
||||
transport : vscodelc.TransportKind.stdio,
|
||||
args : []
|
||||
},
|
||||
debug : {
|
||||
command : serverPath,
|
||||
transport : vscodelc.TransportKind.stdio,
|
||||
args : []
|
||||
}
|
||||
};
|
||||
|
||||
// Configure the client options.
|
||||
const clientOptions: vscodelc.LanguageClientOptions = {
|
||||
documentSelector : [ {scheme : 'file', language : 'mlir'} ],
|
||||
synchronize : {
|
||||
// Notify the server about file changes to *.mlir files contained in the
|
||||
// workspace.
|
||||
fileEvents : vscode.workspace.createFileSystemWatcher('**/*.mlir')
|
||||
}
|
||||
};
|
||||
|
||||
// Create the language client and start the client.
|
||||
client = new vscodelc.LanguageClient('mlir-lsp', 'MLIR Language Client',
|
||||
serverOptions, clientOptions);
|
||||
client.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the extension is deactivated.
|
||||
*/
|
||||
export function deactivate(): Thenable<void>|undefined {
|
||||
if (!client) {
|
||||
return undefined;
|
||||
}
|
||||
return client.stop();
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"outDir": "out",
|
||||
"rootDir": "src",
|
||||
"sourceMap": true
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
".vscode-test"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue