Add prettier and update folding provider

This commit is contained in:
Kolja Lampe
2019-04-12 16:09:42 +02:00
parent 335f29a0b1
commit f72873aaa7
8 changed files with 327 additions and 240 deletions

1
.prettierrc.yaml Normal file
View File

@@ -0,0 +1 @@
trailingComma: "all"

7
.vscode/tasks.json vendored
View File

@@ -28,6 +28,13 @@
"problemMatcher": [ "problemMatcher": [
"$tsc-watch" "$tsc-watch"
] ]
},
{
"type": "npm",
"script": "lint",
"problemMatcher": [
"$tslint5"
]
} }
] ]
} }

51
package-lock.json generated
View File

@@ -155,6 +155,16 @@
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
"dev": true "dev": true
}, },
"eslint-plugin-prettier": {
"version": "2.7.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-2.7.0.tgz",
"integrity": "sha512-CStQYJgALoQBw3FsBzH0VOVDRnJ/ZimUlpLm226U8qgqYJfPOY/CPK6wyRInMxh73HSKg5wyRwdS4BVYYHwokA==",
"dev": true,
"requires": {
"fast-diff": "^1.1.1",
"jest-docblock": "^21.0.0"
}
},
"esprima": { "esprima": {
"version": "4.0.1", "version": "4.0.1",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
@@ -167,6 +177,12 @@
"integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=",
"dev": true "dev": true
}, },
"fast-diff": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.2.0.tgz",
"integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==",
"dev": true
},
"fs.realpath": { "fs.realpath": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
@@ -218,6 +234,12 @@
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=",
"dev": true "dev": true
}, },
"jest-docblock": {
"version": "21.2.0",
"resolved": "https://registry.npmjs.org/jest-docblock/-/jest-docblock-21.2.0.tgz",
"integrity": "sha512-5IZ7sY9dBAYSV+YjQ0Ovb540Ku7AO9Z5o2Cg789xj167iQuZ2cG+z0f3Uct6WeYLbU6aQiM2pCs7sZ+4dotydw==",
"dev": true
},
"js-tokens": { "js-tokens": {
"version": "3.0.2", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz",
@@ -234,6 +256,12 @@
"esprima": "^4.0.0" "esprima": "^4.0.0"
} }
}, },
"lines-and-columns": {
"version": "1.1.6",
"resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.1.6.tgz",
"integrity": "sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=",
"dev": true
},
"minimatch": { "minimatch": {
"version": "3.0.4", "version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
@@ -279,6 +307,12 @@
"integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==", "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==",
"dev": true "dev": true
}, },
"prettier": {
"version": "1.16.4",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-1.16.4.tgz",
"integrity": "sha512-ZzWuos7TI5CKUeQAtFd6Zhm2s6EpAD/ZLApIhsF9pRvRtM1RFo61dM/4MSRUA0SuLugA/zgrZD8m0BaY46Og7g==",
"dev": true
},
"resolve": { "resolve": {
"version": "1.10.0", "version": "1.10.0",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.0.tgz", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.0.tgz",
@@ -342,6 +376,23 @@
"tsutils": "^2.29.0" "tsutils": "^2.29.0"
} }
}, },
"tslint-config-prettier": {
"version": "1.18.0",
"resolved": "https://registry.npmjs.org/tslint-config-prettier/-/tslint-config-prettier-1.18.0.tgz",
"integrity": "sha512-xPw9PgNPLG3iKRxmK7DWr+Ea/SzrvfHtjFt5LBl61gk2UBG/DB9kCXRjv+xyIU1rUtnayLeMUVJBcMX8Z17nDg==",
"dev": true
},
"tslint-plugin-prettier": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/tslint-plugin-prettier/-/tslint-plugin-prettier-2.0.1.tgz",
"integrity": "sha512-4FX9JIx/1rKHIPJNfMb+ooX1gPk5Vg3vNi7+dyFYpLO+O57F4g+b/fo1+W/G0SUOkBLHB/YKScxjX/P+7ZT/Tw==",
"dev": true,
"requires": {
"eslint-plugin-prettier": "^2.2.0",
"lines-and-columns": "^1.1.6",
"tslib": "^1.7.1"
}
},
"tsutils": { "tsutils": {
"version": "2.29.0", "version": "2.29.0",
"resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz", "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz",

View File

@@ -77,12 +77,16 @@
"compile": "tsc -b", "compile": "tsc -b",
"watch": "tsc -b -w", "watch": "tsc -b -w",
"postinstall": "cd client && npm install && cd ../server && npm install && cd ..", "postinstall": "cd client && npm install && cd ../server && npm install && cd ..",
"test": "sh ./scripts/e2e.sh" "test": "sh ./scripts/e2e.sh",
"lint": "tslint -p tsconfig.json"
}, },
"devDependencies": { "devDependencies": {
"@types/mocha": "^5.2.6", "@types/mocha": "^5.2.6",
"@types/node": "^11.13.4", "@types/node": "^11.13.4",
"prettier": "^1.16.4",
"tslint": "^5.15.0", "tslint": "^5.15.0",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.0.1",
"typescript": "3.4.3" "typescript": "3.4.3"
} }
} }

View File

@@ -48,13 +48,11 @@ export class ElmMakeDiagnostics {
} else { } else {
make = cp.spawn(makeCommand, args, { cwd }); make = cp.spawn(makeCommand, args, { cwd });
} }
// output is actually optional
// (fixed in https://github.com/Microsoft/vscode/commit/b4917afe9bdee0e9e67f4094e764f6a72a997c70, if (!make.stderr) { return; }
// but unreleased at this time)
const errorLinesFromElmMake: readline.ReadLine = readline.createInterface( const errorLinesFromElmMake: readline.ReadLine = readline.createInterface(
{ {
input: make.stderr, input: make.stderr,
output: undefined,
}, },
); );
const lines: IElmIssue[] = []; const lines: IElmIssue[] = [];

View File

@@ -1,6 +1,11 @@
import { SyntaxNode, Tree } from "tree-sitter"; import { SyntaxNode, Tree } from "tree-sitter";
import { FoldingRange, FoldingRangeKind, FoldingRangeRequest, import {
FoldingRangeRequestParam, IConnection } from "vscode-languageserver"; FoldingRange,
FoldingRangeKind,
FoldingRangeRequest,
FoldingRangeRequestParam,
IConnection
} from "vscode-languageserver";
import { IForest } from "../forest"; import { IForest } from "../forest";
export class FoldingRangeProvider { export class FoldingRangeProvider {
@@ -10,31 +15,42 @@ export class FoldingRangeProvider {
"if", "if",
"case", "case",
"func_statement", "func_statement",
"block_comment",
"record_type",
"record_expr"
]); ]);
constructor(connection: IConnection, forest: IForest) { constructor(connection: IConnection, forest: IForest) {
this.connection = connection; this.connection = connection;
this.forest = forest; this.forest = forest;
this.connection.onRequest(FoldingRangeRequest.type, this.handleFoldingRange); this.connection.onRequest(
FoldingRangeRequest.type,
this.handleFoldingRange
);
} }
protected handleFoldingRange = async ( protected handleFoldingRange = async (
param: FoldingRangeRequestParam, param: FoldingRangeRequestParam
): Promise<FoldingRange[]> => { ): Promise<FoldingRange[]> => {
const folds: FoldingRange[] = []; const folds: FoldingRange[] = [];
const tree: Tree | undefined = this.forest.getTree(param.textDocument.uri); const tree: Tree | undefined = this.forest.getTree(param.textDocument.uri);
const traverse: (node: SyntaxNode) => void = (node: SyntaxNode): void => { const traverse: (node: SyntaxNode) => void = (node: SyntaxNode): void => {
if (node.parent && node.parent.lastChild && !node.isNamed && this.FOLD_CONSTRUCTS.has(node.type)) { if (
node.parent &&
node.parent.lastChild &&
!node.isNamed &&
this.FOLD_CONSTRUCTS.has(node.type)
) {
const endNode: SyntaxNode = node.parent.lastChild; const endNode: SyntaxNode = node.parent.lastChild;
folds.push({ folds.push({
endCharacter: node.endPosition.column, endCharacter: node.endPosition.column,
endLine: endNode.endPosition.row, endLine: endNode.endPosition.row,
kind: FoldingRangeKind.Region, kind: FoldingRangeKind.Region,
startCharacter: node.startPosition.column, startCharacter: node.startPosition.column,
startLine: node.startPosition.row, startLine: node.startPosition.row
}); });
} }
for (const childNode of node.children) { for (const childNode of node.children) {
@@ -46,5 +62,5 @@ export class FoldingRangeProvider {
} }
return folds; return folds;
} };
} }

View File

@@ -41,14 +41,9 @@ export function execCmd(
cmd: string, cmd: string,
options: IExecCmdOptions = {}, options: IExecCmdOptions = {},
elmRootPath: URI, elmRootPath: URI,
connection: IConnection, connection: IConnection
): IExecutingCmd { ): IExecutingCmd {
const { const { onStart, onStdout, onStderr, onExit } = options;
onStart,
onStdout,
onStderr,
onExit,
} = options;
let childProcess: cp.ChildProcess; let childProcess: cp.ChildProcess;
let firstResponse = true; let firstResponse = true;
let wasKilledbyUs = false; let wasKilledbyUs = false;
@@ -57,7 +52,15 @@ export function execCmd(
const cmdArguments = options ? options.cmdArguments : []; const cmdArguments = options ? options.cmdArguments : [];
const fullCommand = cmd + " " + (cmdArguments || []).join(" "); const fullCommand = cmd + " " + (cmdArguments || []).join(" ");
childProcess = cp.exec(fullCommand, { cwd: elmRootPath.fsPath }, handleExit); childProcess = cp.exec(
fullCommand,
{ cwd: elmRootPath.fsPath },
handleExit
);
if (!childProcess.stdout) {
return;
}
childProcess.stdout.on("data", (data: Buffer) => { childProcess.stdout.on("data", (data: Buffer) => {
if (firstResponse && onStart) { if (firstResponse && onStart) {
@@ -69,6 +72,9 @@ export function execCmd(
} }
}); });
if (!childProcess.stderr) {
return;
}
childProcess.stderr.on("data", (data: Buffer) => { childProcess.stderr.on("data", (data: Buffer) => {
if (firstResponse && onStart) { if (firstResponse && onStart) {
onStart(); onStart();
@@ -79,7 +85,11 @@ export function execCmd(
} }
}); });
function handleExit(error: cp.ExecException | null, stdout: string | Buffer, stderr: string | Buffer) { function handleExit(
error: cp.ExecException | null,
stdout: string | Buffer,
stderr: string | Buffer
) {
IexecutingCmd.isRunning = false; IexecutingCmd.isRunning = false;
if (onExit) { if (onExit) {
onExit(); onExit();
@@ -97,7 +107,7 @@ export function execCmd(
if (cmdWasNotFound) { if (cmdWasNotFound) {
const notFoundText = options ? options.notFoundText : ""; const notFoundText = options ? options.notFoundText : "";
connection.window.showErrorMessage( connection.window.showErrorMessage(
`${cmdName} is not available in your path. ` + notFoundText, `${cmdName} is not available in your path. ` + notFoundText
); );
} else { } else {
connection.window.showErrorMessage(error.message); connection.window.showErrorMessage(error.message);

View File

@@ -1,9 +1,9 @@
{ {
"defaultSeverity": "error", "defaultSeverity": "error",
"extends": [ "extends": ["tslint:recommended", "tslint-config-prettier"],
"tslint:recommended"
],
"jsRules": {}, "jsRules": {},
"rules": {}, "rules": {
"rulesDirectory": [] "prettier": true
},
"rulesDirectory": ["tslint-plugin-prettier"]
} }