Skip to content

Commit 9c6cd78

Browse files
committed
Updates to vscode extension.
Clean up execution of mro tool using promisify to simplify error handling. Use void instead of await for error reporting so that the function doesn't report that it's still running until the user dismisses the error message. Write to the process using Readable.pipe, so that writing happens asynchronously. Move launch config to workspace root, so that it actually works. Kind of, anyway. Update lint config, and typescript config to es2020.
1 parent 873086c commit 9c6cd78

13 files changed

+116
-59
lines changed

.vscode/launch.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"version": "0.3.0",
3+
"configurations": [
4+
{
5+
"name": "Run Extension",
6+
"type": "extensionHost",
7+
"request": "launch",
8+
"runtimeExecutable": "${execPath}",
9+
"args": [
10+
"--extensionDevelopmentPath=${workspaceFolder}/tools/syntax/vscode"
11+
],
12+
"outFiles": [
13+
"${workspaceFolder}/tools/syntax/vscode/syntaxes/Martianlang.tmLanguage.json",
14+
"${workspaceFolder}/tools/syntax/vscode/language-configuration.json",
15+
"${workspaceFolder}/tools/syntax/vscode/package.json",
16+
"${workspaceFolder}/tools/syntax/vscode/out/**/*.js",
17+
"${workspaceFolder}/tools/syntax/vscode/out/**/*.js.map"
18+
],
19+
"preLaunchTask": "vscode"
20+
},
21+
]
22+
}

.vscode/tasks.json

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// See https://go.microsoft.com/fwlink/?LinkId=733558
2+
// for the documentation about the tasks.json format
3+
{
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"label": "Go test",
8+
"type": "shell",
9+
"command": "go test ./martian/... ./cmd/...",
10+
"group": {
11+
"kind":"test",
12+
"isDefault": true
13+
}
14+
},
15+
{
16+
"label": "Build",
17+
"type": "shell",
18+
"command": "make",
19+
"group": {
20+
"kind":"build",
21+
"isDefault": true
22+
}
23+
},
24+
{
25+
"label": "vscode",
26+
"type": "npm",
27+
"path": "tools/syntax/vscode",
28+
"script": "watch",
29+
"problemMatcher": "$tsc-watch",
30+
"isBackground": true,
31+
"presentation": {
32+
"reveal": "never"
33+
},
34+
"group": {
35+
"kind": "build",
36+
"isDefault": true
37+
}
38+
}
39+
]
40+
}

Makefile

+1-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ unexport GOPATH
1919
export GO111MODULE=on
2020
export GOBIN=$(PWD)/bin
2121

22-
.PHONY: $(GOBINS) grammar web $(GOTESTS) coverage.out govet all-bins $(GOBIN)/sum_squares longtests mrs integration_prereqs vscode vscode-test
22+
.PHONY: $(GOBINS) grammar web $(GOTESTS) coverage.out govet all-bins $(GOBIN)/sum_squares longtests integration_prereqs vscode vscode-test
2323

2424
#
2525
# Targets for development builds.
@@ -42,12 +42,6 @@ grammar: martian/syntax/grammar.go
4242
$(GOBINS):
4343
go install $(GO_FLAGS) ./cmd/$@
4444

45-
mrs: $(GOBIN)/mrs
46-
47-
$(GOBIN)/mrs: mrp
48-
rm -f $(GOBIN)/mrs && ln -s mrp $(GOBIN)/mrs
49-
50-
5145
all-bins:
5246
go install $(GO_FLAGS) ./cmd/...
5347

tools/syntax/vscode/.eslintrc.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ module.exports = {
44
"node": true
55
},
66
"extends": [
7+
"eslint:recommended",
78
"plugin:@typescript-eslint/recommended",
89
"plugin:@typescript-eslint/recommended-requiring-type-checking"
910
],
1011
"parser": "@typescript-eslint/parser",
1112
"parserOptions": {
13+
"ecmaVersion": 2020,
1214
"project": "tsconfig.json",
13-
"sourceType": "module"
15+
"sourceType": "module",
16+
"tsconfigRootDir": __dirname,
1417
},
1518
"plugins": [
1619
"eslint-plugin-jsdoc",
@@ -65,7 +68,6 @@ module.exports = {
6568
}
6669
],
6770
"@typescript-eslint/no-unused-expressions": "error",
68-
"@typescript-eslint/no-use-before-define": "off",
6971
"@typescript-eslint/no-var-requires": "error",
7072
"@typescript-eslint/prefer-for-of": "error",
7173
"@typescript-eslint/prefer-function-type": "error",
@@ -133,7 +135,6 @@ module.exports = {
133135
"no-unsafe-finally": "error",
134136
"no-unused-expressions": "error",
135137
"no-unused-labels": "error",
136-
"no-use-before-define": "off",
137138
"no-var": "error",
138139
"object-shorthand": "error",
139140
"one-var": [
@@ -153,5 +154,10 @@ module.exports = {
153154
],
154155
"use-isnan": "error",
155156
"valid-typeof": "off"
156-
}
157+
},
158+
"ignorePatterns": [
159+
"out",
160+
"dist",
161+
"**/*.d.ts"
162+
]
157163
};

tools/syntax/vscode/.vscode/launch.json

-14
This file was deleted.

tools/syntax/vscode/.vscodeignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ syntaxes/Martianlang.YAML-tmLanguage
88
Makefile
99
tslint.json
1010
tsconfig.json
11-
out/**/*.map
11+
out/.eslintrc*
12+
out/**/*.map

tools/syntax/vscode/LICENSE

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../LICENSE

tools/syntax/vscode/Makefile

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ MODULES=extension format_provider mro
44
OUTS=$(addprefix out/src/, $(addsuffix .js, $(MODULES)) $(addsuffix .js.map, $(MODULES)))
55
INS=$(addprefix src/, $(addsuffix .ts, $(MODULES)))
66

7-
.PHONY: all
7+
.PHONY: all package
88

99
all: $(OUTS) syntaxes/Martianlang.tmLanguage.json
1010

11-
$(OUTS): $(INS) tsconfig.json
11+
$(OUTS): $(INS) tsconfig.json package.json package-lock.json
1212
$(TSC) -p ./
1313

1414
syntaxes/Martianlang.tmLanguage.json: syntaxes/Martianlang.YAML-tmLanguage
1515
npx js-yaml $< > $@
1616

17+
package: $(OUTS) .vscodeignore language-configuration.json
18+
vsce package
19+
1720
clean:
1821
rm -rf out/ node_modules/

tools/syntax/vscode/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/syntax/vscode/package.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "martian-lang",
33
"displayName": "Martian MRO language",
44
"description": "Supports syntax highlighting and indenting for Martian (https://martian-lang.org) .mro files.",
5-
"version": "0.0.3",
5+
"version": "0.0.4",
66
"publisher": "MartianLang",
77
"license": "MIT",
88
"engines": {
@@ -70,9 +70,15 @@
7070
}
7171
}
7272
},
73+
"extensionKind": [
74+
"workspace",
75+
"ui"
76+
],
7377
"scripts": {
74-
"check-lint": "npx eslint -f stylish src/*.ts",
78+
"check-lint": "npx eslint -f stylish . --ext ts",
79+
"lint": "npx eslint -f stylish . --ext ts",
7580
"compile": "make",
81+
"watch": "tsc -watch -p ./",
7682
"vscode:prepublish": "make"
7783
},
7884
"devDependencies": {

tools/syntax/vscode/src/format_provider.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class MroFormatProvider
4242
];
4343
return edits;
4444
} catch (err) {
45-
await vscode.window.showErrorMessage(String(err));
45+
void vscode.window.showErrorMessage(String(err));
4646
return [];
4747
}
4848
}

tools/syntax/vscode/src/mro.ts

+20-23
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import * as child_process from "child_process";
2+
import { promisify } from "util";
3+
import { Readable } from "stream";
24
import * as path from "path";
35
import * as fs from "fs";
46
import * as process from "process";
57
import * as vscode from "vscode";
68

9+
const execFile = promisify(child_process.execFile);
10+
711
export async function mroFormat(
812
fileContent: string,
913
fileName: string,
@@ -82,35 +86,28 @@ async function executeMro(
8286
mropath: string,
8387
token: vscode.CancellationToken,
8488
): Promise<{ stdout: string; stderr: string }> {
85-
const execOptions = {
89+
const execOptions: child_process.ExecOptions = {
8690
env: getMroEnv(mropath, workspacePath),
8791
maxBuffer: Number.MAX_SAFE_INTEGER,
8892
};
8993
const exePath = await getDefaultMroExecutablePath(workspacePath);
9094
if (token.isCancellationRequested) {
9195
return { stdout: "", stderr: "" };
9296
}
93-
return await new Promise((resolve, reject) => {
94-
const proc = child_process.execFile(
95-
exePath,
96-
args,
97-
execOptions,
98-
(error: Error, stdout: string, stderr: string) => {
99-
if (!error) {
100-
resolve({ stdout, stderr });
101-
} else {
102-
reject(error);
103-
}
104-
},
105-
);
106-
token.onCancellationRequested(() => proc.kill());
107-
if (token.isCancellationRequested) {
108-
proc.kill();
109-
return;
97+
const procPromise = execFile(
98+
exePath,
99+
args,
100+
execOptions,
101+
);
102+
const proc = procPromise.child;
103+
token.onCancellationRequested(() => proc.kill());
104+
if (token.isCancellationRequested) {
105+
proc.kill();
106+
if (proc.stdin) {
107+
proc.stdin.end();
110108
}
111-
// Write the file being formatted to stdin and close the stream so
112-
// that the mro process continues.
113-
proc.stdin?.write(fileContent);
114-
proc.stdin?.end();
115-
});
109+
} else if (proc.stdin) {
110+
Readable.from([fileContent]).pipe(proc.stdin, { end: true });
111+
}
112+
return await procPromise;
116113
}

tools/syntax/vscode/tsconfig.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
{
22
"compilerOptions": {
33
"module": "commonjs",
4-
"target": "es6",
4+
"target": "ES2020",
55
"outDir": "out",
66
"lib": [
7-
"es6"
7+
"ES2020"
88
],
99
"sourceMap": true,
1010
"rootDir": ".",
1111
"alwaysStrict": true,
1212
"allowJs": true,
13-
"strictNullChecks": true
13+
"strictNullChecks": true,
14+
"strict": true
1415
},
1516
"exclude": [
1617
"node_modules",

0 commit comments

Comments
 (0)