Add VS Code extension.

This commit is contained in:
Qi Xiao 2022-06-05 12:14:58 +01:00
parent e43968569b
commit b24421170a
12 changed files with 452 additions and 2 deletions

View File

@ -1,2 +1,3 @@
[codespell]
ignore-words-list = upto,nd,ba,doas,fo,struc,shouldbe,iterm,lates,testof
skip = ./vscode/node_modules

2
.gitignore vendored
View File

@ -21,8 +21,6 @@ _testmain.go
*.exe
/.vscode/
# Project specific
cover
/_bin/

13
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
}
]
}

2
vscode/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/node_modules
/*.vsix

12
vscode/HACKING.md Normal file
View File

@ -0,0 +1,12 @@
# Developing the Visual Studio Code extension
Follow these steps to run the extension from source:
1. Install NPM dependencies: `npm install`.
2. Open the repository root (**not** this directory) in VS Code, and choose
"Run Extension" from the
[debug side bar](https://code.visualstudio.com/docs/editor/debugging).
See Visual Studio Code's documentation on
[developing language extensions](https://code.visualstudio.com/api/language-extensions/overview).

11
vscode/README.md Normal file
View File

@ -0,0 +1,11 @@
# Elvish for Visual Studio Code
This extension provides support for [Elvish](https://elv.sh) in
[Visual Studio Code](https://code.visualstudio.com).
Current functionalities:
- Syntax highlighting and configuration (e.g. bracket pairs)
- Error checking and basic autocompletion, using Elvish's builtin language
server

View File

@ -0,0 +1,117 @@
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "Elvish",
"scopeName": "source.elvish",
"fileTypes": [
"elv"
],
"patterns": [
{
"name": "string.quoted.double.elvish",
"begin": "\"",
"end": "\"",
"patterns": [
{
"name": "constant.character.escape.elvish",
"match": "\\\\."
}
]
},
{
"name": "string.quoted.single.elvish",
"begin": "'",
"end": "'"
},
{
"name": "comment.line.number-sign.elvish",
"begin": "#",
"end": "$"
},
{
"name": "variable.other.elvish",
"match": "\\$[\\w\\d_:~-]+"
},
{
"match": "(?<=^|\\{ |\\{\t|\\(|\\||\\;)\\s*(var|set|tmp|del)((\\s+[\\w\\d_:~-]+)*)",
"captures": {
"1": {
"name": "keyword.other.elvish"
},
"2": {
"name": "variable.other.elvish"
}
}
},
{
"match": "(?<=^|\\{ |\\{\t|\\(|\\||\\;)\\s*(for)\\s+([\\w\\d_:~-]+)",
"captures": {
"1": {
"name": "keyword.control.elvish"
},
"2": {
"name": "variable.other.elvish"
}
}
},
{
"match": "}\\s+(catch|except)\\s+([\\w\\d_:~-]+)",
"captures": {
"1": {
"name": "keyword.control.elvish"
},
"2": {
"name": "variable.other.elvish"
}
}
},
{
"match": "(?<=^|\\{ |\\{\t|\\(|\\||\\;)\\s*(nop|!=|!=s|%|\\*|\\+|-gc|-ifaddrs|-log|-override-wcwidth|-stack|-|/|<|<=|<=s|<s|==|==s|>|>=|>=s|>s|all|assoc|base|bool|break|call|cd|compare|constantly|continue|count|defer|deprecate|dissoc|drop|each|eawk|echo|eq|eval|exact-num|exec|exit|external|fail|fg|float64|from-json|from-lines|from-terminated|get-env|has-env|has-external|has-key|has-value|is|keys|kind-of|make-map|multi-error|nop|not-eq|not|ns|num|one|only-bytes|only-values|order|peach|pprint|print|printf|put|rand|randint|range|read-line|read-upto|repeat|repr|resolve|return|run-parallel|search-external|set-env|show|sleep|slurp|src|styled|styled-segment|take|tilde-abbr|time|to-json|to-lines|to-string|to-terminated|unset-env|use-mod|wcswidth)(?=[\\s)}<>;|&])",
"captures": {
"1": {
"name": "support.function"
}
}
},
{
"match": "(?<=^|\\{ |\\{\t|\\(|\\||\\;)\\s*(and|or|coalesce)(?=[\\s)}<>;|&])",
"captures": {
"1": {
"name": "keyword.operator.elvish"
}
}
},
{
"match": "(?<=^|\\{ |\\{\t|\\(|\\||\\;)\\s*(use|var|set|tmp|del|pragma|fn)(?=[\\s)}<>;|&])",
"captures": {
"1": {
"name": "keyword.other.elvish"
}
}
},
{
"match": "(?<=^|\\{ |\\{\t|\\(|\\||\\;)\\s*(while|for|try|if)(?=[\\s)}<>;|&])",
"captures": {
"1": {
"name": "keyword.control.elvish"
}
}
},
{
"match": "}\\s+(elif|else|finally)\\s+([\\w\\d_:~-]+)",
"captures": {
"1": {
"name": "keyword.control.elvish"
}
}
},
{
"name": "keyword.operator.elvish",
"match": "[*?|&;<>()\\[\\]{}]"
}
]
}

24
vscode/extension.js Normal file
View File

@ -0,0 +1,24 @@
const { LanguageClient } = require("vscode-languageclient/node");
let client;
function activate() {
client = new LanguageClient(
"elvish",
"Elvish Language Server",
{ command: "elvish", args: ["-lsp"] },
{ documentSelector: [{ scheme: "file", language: "elvish" }] }
);
client.start();
}
function deactivate() {
if (client) {
return client.stop();
}
}
module.exports = {
activate,
deactivate,
};

BIN
vscode/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

View File

@ -0,0 +1,24 @@
{
"comments": {
"lineComment": "#",
},
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
"autoClosingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
],
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
]
}

192
vscode/package-lock.json generated Normal file
View File

@ -0,0 +1,192 @@
{
"name": "elvish",
"version": "0.19.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "elvish",
"version": "0.19.0",
"dependencies": {
"vscode-languageclient": "^7.0.0"
},
"engines": {
"vscode": "^1.65.0"
}
},
"node_modules/balanced-match": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="
},
"node_modules/brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"dependencies": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
}
},
"node_modules/concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
},
"node_modules/lru-cache": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
"dependencies": {
"yallist": "^4.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/minimatch": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
"dependencies": {
"brace-expansion": "^1.1.7"
},
"engines": {
"node": "*"
}
},
"node_modules/semver": {
"version": "7.3.5",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz",
"integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==",
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/vscode-jsonrpc": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-6.0.0.tgz",
"integrity": "sha512-wnJA4BnEjOSyFMvjZdpiOwhSq9uDoK8e/kpRJDTaMYzwlkrhG1fwDIZI94CLsLzlCK5cIbMMtFlJlfR57Lavmg==",
"engines": {
"node": ">=8.0.0 || >=10.0.0"
}
},
"node_modules/vscode-languageclient": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-7.0.0.tgz",
"integrity": "sha512-P9AXdAPlsCgslpP9pRxYPqkNYV7Xq8300/aZDpO35j1fJm/ncize8iGswzYlcvFw5DQUx4eVk+KvfXdL0rehNg==",
"dependencies": {
"minimatch": "^3.0.4",
"semver": "^7.3.4",
"vscode-languageserver-protocol": "3.16.0"
},
"engines": {
"vscode": "^1.52.0"
}
},
"node_modules/vscode-languageserver-protocol": {
"version": "3.16.0",
"resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.16.0.tgz",
"integrity": "sha512-sdeUoAawceQdgIfTI+sdcwkiK2KU+2cbEYA0agzM2uqaUy2UpnnGHtWTHVEtS0ES4zHU0eMFRGN+oQgDxlD66A==",
"dependencies": {
"vscode-jsonrpc": "6.0.0",
"vscode-languageserver-types": "3.16.0"
}
},
"node_modules/vscode-languageserver-types": {
"version": "3.16.0",
"resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.16.0.tgz",
"integrity": "sha512-k8luDIWJWyenLc5ToFQQMaSrqCHiLwyKPHKPQZ5zz21vM+vIVUSvsRpcbiECH4WR88K2XZqc4ScRcZ7nk/jbeA=="
},
"node_modules/yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
}
},
"dependencies": {
"balanced-match": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="
},
"brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
}
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
},
"lru-cache": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
"requires": {
"yallist": "^4.0.0"
}
},
"minimatch": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
"integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
"requires": {
"brace-expansion": "^1.1.7"
}
},
"semver": {
"version": "7.3.5",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz",
"integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==",
"requires": {
"lru-cache": "^6.0.0"
}
},
"vscode-jsonrpc": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-6.0.0.tgz",
"integrity": "sha512-wnJA4BnEjOSyFMvjZdpiOwhSq9uDoK8e/kpRJDTaMYzwlkrhG1fwDIZI94CLsLzlCK5cIbMMtFlJlfR57Lavmg=="
},
"vscode-languageclient": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-7.0.0.tgz",
"integrity": "sha512-P9AXdAPlsCgslpP9pRxYPqkNYV7Xq8300/aZDpO35j1fJm/ncize8iGswzYlcvFw5DQUx4eVk+KvfXdL0rehNg==",
"requires": {
"minimatch": "^3.0.4",
"semver": "^7.3.4",
"vscode-languageserver-protocol": "3.16.0"
}
},
"vscode-languageserver-protocol": {
"version": "3.16.0",
"resolved": "https://registry.npmjs.org/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.16.0.tgz",
"integrity": "sha512-sdeUoAawceQdgIfTI+sdcwkiK2KU+2cbEYA0agzM2uqaUy2UpnnGHtWTHVEtS0ES4zHU0eMFRGN+oQgDxlD66A==",
"requires": {
"vscode-jsonrpc": "6.0.0",
"vscode-languageserver-types": "3.16.0"
}
},
"vscode-languageserver-types": {
"version": "3.16.0",
"resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.16.0.tgz",
"integrity": "sha512-k8luDIWJWyenLc5ToFQQMaSrqCHiLwyKPHKPQZ5zz21vM+vIVUSvsRpcbiECH4WR88K2XZqc4ScRcZ7nk/jbeA=="
},
"yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
}
}
}

56
vscode/package.json Normal file
View File

@ -0,0 +1,56 @@
{
"name": "elvish",
"displayName": "Elvish",
"description": "Elvish language support for Visual Studio Code",
"version": "0.1.0",
"publisher": "elves",
"license": "BSD-2-Clause",
"icon": "icon.png",
"repository": {
"type": "git",
"url": "https://github.com/elves/elvish"
},
"engines": {
"vscode": "^1.65.0"
},
"categories": [
"Programming Languages"
],
"activationEvents": [
"onLanguage:elvish"
],
"main": "./extension.js",
"contributes": {
"languages": [{
"id": "elvish",
"aliases": ["Elvish", "elvish"],
"extensions": [".elv"],
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "elvish",
"scopeName": "source.elvish",
"path": "./elvish.tmLanguage.json"
}],
"configuration": {
"title": "Elvish",
"properties": {
"elvish.trace.server": {
"type": "string",
"enum": [
"off",
"messages",
"verbose"
],
"default": "off",
"description": "Trace communication between VS Code and the Elvish language server. Trace messages are shown in the Elvish Language Server output channel."
}
}
}
},
"scripts": {
},
"dependencies": {
"vscode-languageclient": "^7.0.0"
}
}