diff --git a/package-lock.json b/package-lock.json index 97a119dc..83fb9117 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,13 +22,13 @@ "vscode-languageserver": "^9.0.1", "vscode-languageserver-textdocument": "1.0.11", "vscode-uri": "^3.0.8", - "web-tree-sitter": "^0.20.8" + "web-tree-sitter": "^0.25.3" }, "bin": { "elm-language-server": "out/node/index.js" }, "devDependencies": { - "@elm-tooling/tree-sitter-elm": "^5.7.0", + "@elm-tooling/tree-sitter-elm": "^5.8.0", "@types/jest": "^29.5.11", "@types/node": "^20.10.5", "@typescript-eslint/eslint-plugin": "^6.15.0", @@ -43,7 +43,7 @@ "jest-diff": "^29.7.0", "jest-mock-extended": "^3.0.5", "prettier": "^3.1.1", - "tree-sitter-cli": "^0.20.8", + "tree-sitter-cli": "^0.25.3", "ts-jest": "^29.1.1", "ts-node": "^10.9.2", "typescript": "5.3.3" @@ -835,13 +835,23 @@ } }, "node_modules/@elm-tooling/tree-sitter-elm": { - "version": "5.7.0", - "resolved": "https://registry.npmjs.org/@elm-tooling/tree-sitter-elm/-/tree-sitter-elm-5.7.0.tgz", - "integrity": "sha512-ezKHIczyZx6bFtktLFRPbvW/7LzL0XdI1Y5OoxkNaSrfh2m0Bm8yilbB4Hya4VQN7mJktXhhzAMGab8nKm/2Bw==", + "version": "5.8.0", + "resolved": "https://registry.npmjs.org/@elm-tooling/tree-sitter-elm/-/tree-sitter-elm-5.8.0.tgz", + "integrity": "sha512-AOCJlUumWqetQxXkRf3ZpztbTNeyBB2NfuOKokZgLSF7TboctgOCpR7MMrJk9/uGn8rPbcg1gOyhZOQBl1MOpQ==", "dev": true, "hasInstallScript": true, + "license": "MIT", "dependencies": { - "nan": "^2.18.0" + "node-addon-api": "^8.2.1", + "node-gyp-build": "^4.8.2" + }, + "peerDependencies": { + "tree-sitter": "^0.21.1" + }, + "peerDependenciesMeta": { + "tree-sitter": { + "optional": true + } } }, "node_modules/@eslint-community/eslint-utils": { @@ -5160,18 +5170,34 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, - "node_modules/nan": { - "version": "2.18.0", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.18.0.tgz", - "integrity": "sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w==", - "dev": true - }, "node_modules/natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", "dev": true }, + "node_modules/node-addon-api": { + "version": "8.3.1", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.3.1.tgz", + "integrity": "sha512-lytcDEdxKjGJPTLEfW4mYMigRezMlyJY8W4wxJK8zE533Jlb8L8dRuObJFWg2P+AuOIxoCgKF+2Oq4d4Zd0OUA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18 || ^20 || >= 21" + } + }, + "node_modules/node-gyp-build": { + "version": "4.8.4", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.4.tgz", + "integrity": "sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==", + "dev": true, + "license": "MIT", + "bin": { + "node-gyp-build": "bin.js", + "node-gyp-build-optional": "optional.js", + "node-gyp-build-test": "build-test.js" + } + }, "node_modules/node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -6137,13 +6163,17 @@ "dev": true }, "node_modules/tree-sitter-cli": { - "version": "0.20.8", - "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.20.8.tgz", - "integrity": "sha512-XjTcS3wdTy/2cc/ptMLc/WRyOLECRYcMTrSWyhZnj1oGSOWbHLTklgsgRICU3cPfb0vy+oZCC33M43u6R1HSCA==", + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.25.3.tgz", + "integrity": "sha512-Bk6ZUXG+cKnwZpfR/te4NDrKld90p6350eqWlbLwSpV9/8vmL/x8LCw+3k7quY9oMDaYoMXHMvokXJbkM5A7bA==", "dev": true, "hasInstallScript": true, + "license": "MIT", "bin": { "tree-sitter": "cli.js" + }, + "engines": { + "node": ">=12.0.0" } }, "node_modules/trough": { @@ -6575,9 +6605,10 @@ } }, "node_modules/web-tree-sitter": { - "version": "0.20.8", - "resolved": "https://registry.npmjs.org/web-tree-sitter/-/web-tree-sitter-0.20.8.tgz", - "integrity": "sha512-weOVgZ3aAARgdnb220GqYuh7+rZU0Ka9k9yfKtGAzEYMa6GgiCzW9JjQRJyCJakvibQW+dfjJdihjInKuuCAUQ==" + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/web-tree-sitter/-/web-tree-sitter-0.25.3.tgz", + "integrity": "sha512-e0hdXG+nJ18Zd/QJFhSx0DNTSMz7miwUjKyJ/lglTnZo6ke08++BQzXkaeaqnGJFi9qq+nPJg2L8hYAjduToHQ==", + "license": "MIT" }, "node_modules/which": { "version": "2.0.2", @@ -7303,12 +7334,13 @@ } }, "@elm-tooling/tree-sitter-elm": { - "version": "5.7.0", - "resolved": "https://registry.npmjs.org/@elm-tooling/tree-sitter-elm/-/tree-sitter-elm-5.7.0.tgz", - "integrity": "sha512-ezKHIczyZx6bFtktLFRPbvW/7LzL0XdI1Y5OoxkNaSrfh2m0Bm8yilbB4Hya4VQN7mJktXhhzAMGab8nKm/2Bw==", + "version": "5.8.0", + "resolved": "https://registry.npmjs.org/@elm-tooling/tree-sitter-elm/-/tree-sitter-elm-5.8.0.tgz", + "integrity": "sha512-AOCJlUumWqetQxXkRf3ZpztbTNeyBB2NfuOKokZgLSF7TboctgOCpR7MMrJk9/uGn8rPbcg1gOyhZOQBl1MOpQ==", "dev": true, "requires": { - "nan": "^2.18.0" + "node-addon-api": "^8.2.1", + "node-gyp-build": "^4.8.2" } }, "@eslint-community/eslint-utils": { @@ -10451,18 +10483,24 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, - "nan": { - "version": "2.18.0", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.18.0.tgz", - "integrity": "sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w==", - "dev": true - }, "natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", "dev": true }, + "node-addon-api": { + "version": "8.3.1", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-8.3.1.tgz", + "integrity": "sha512-lytcDEdxKjGJPTLEfW4mYMigRezMlyJY8W4wxJK8zE533Jlb8L8dRuObJFWg2P+AuOIxoCgKF+2Oq4d4Zd0OUA==", + "dev": true + }, + "node-gyp-build": { + "version": "4.8.4", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.4.tgz", + "integrity": "sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==", + "dev": true + }, "node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -11162,9 +11200,9 @@ "dev": true }, "tree-sitter-cli": { - "version": "0.20.8", - "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.20.8.tgz", - "integrity": "sha512-XjTcS3wdTy/2cc/ptMLc/WRyOLECRYcMTrSWyhZnj1oGSOWbHLTklgsgRICU3cPfb0vy+oZCC33M43u6R1HSCA==", + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.25.3.tgz", + "integrity": "sha512-Bk6ZUXG+cKnwZpfR/te4NDrKld90p6350eqWlbLwSpV9/8vmL/x8LCw+3k7quY9oMDaYoMXHMvokXJbkM5A7bA==", "dev": true }, "trough": { @@ -11459,9 +11497,9 @@ } }, "web-tree-sitter": { - "version": "0.20.8", - "resolved": "https://registry.npmjs.org/web-tree-sitter/-/web-tree-sitter-0.20.8.tgz", - "integrity": "sha512-weOVgZ3aAARgdnb220GqYuh7+rZU0Ka9k9yfKtGAzEYMa6GgiCzW9JjQRJyCJakvibQW+dfjJdihjInKuuCAUQ==" + "version": "0.25.3", + "resolved": "https://registry.npmjs.org/web-tree-sitter/-/web-tree-sitter-0.25.3.tgz", + "integrity": "sha512-e0hdXG+nJ18Zd/QJFhSx0DNTSMz7miwUjKyJ/lglTnZo6ke08++BQzXkaeaqnGJFi9qq+nPJg2L8hYAjduToHQ==" }, "which": { "version": "2.0.2", diff --git a/package.json b/package.json index 1ede5503..faf5ef27 100644 --- a/package.json +++ b/package.json @@ -29,10 +29,10 @@ "vscode-languageserver": "^9.0.1", "vscode-languageserver-textdocument": "1.0.11", "vscode-uri": "^3.0.8", - "web-tree-sitter": "^0.20.8" + "web-tree-sitter": "^0.25.3" }, "devDependencies": { - "@elm-tooling/tree-sitter-elm": "^5.7.0", + "@elm-tooling/tree-sitter-elm": "^5.8.0", "@types/jest": "^29.5.11", "@types/node": "^20.10.5", "@typescript-eslint/eslint-plugin": "^6.15.0", @@ -47,7 +47,7 @@ "jest-diff": "^29.7.0", "jest-mock-extended": "^3.0.5", "prettier": "^3.1.1", - "tree-sitter-cli": "^0.20.8", + "tree-sitter-cli": "^0.25.3", "ts-jest": "^29.1.1", "ts-node": "^10.9.2", "typescript": "5.3.3" @@ -62,7 +62,7 @@ "watch": "npm run copy-wasm && tsc -watch -p ./", "lint": "eslint -c .eslintrc.js --ext .ts src", "lint:fix": "eslint --fix -c .eslintrc.js --ext .ts src", - "build-tree-sitter": "tree-sitter build-wasm ./node_modules/@elm-tooling/tree-sitter-elm", + "build-tree-sitter": "tree-sitter build --wasm ./node_modules/@elm-tooling/tree-sitter-elm", "test": "jest --coverage", "generate-toc": "doctoc README.md" }, diff --git a/src/common/index.ts b/src/common/index.ts index d1a64780..3168ebcf 100644 --- a/src/common/index.ts +++ b/src/common/index.ts @@ -7,7 +7,7 @@ import { InitializeResult, } from "vscode-languageserver"; -import Parser from "web-tree-sitter"; +import { Parser, Language } from "web-tree-sitter"; import { CapabilityCalculator } from "./capabilityCalculator"; import { ASTProvider } from "./providers"; import { @@ -64,7 +64,7 @@ export function startCommonServer( connection.console.info( `Loading Elm tree-sitter syntax from ${pathToWasm}`, ); - const language = await Parser.Language.load(pathToWasm); + const language = await Language.load(pathToWasm); const parser = container.resolve("Parser"); parser.setLanguage(language); diff --git a/src/common/providers/astProvider.ts b/src/common/providers/astProvider.ts index 8571b5f9..57ef11de 100644 --- a/src/common/providers/astProvider.ts +++ b/src/common/providers/astProvider.ts @@ -8,7 +8,7 @@ import { FileChangeType, } from "vscode-languageserver"; import { URI } from "vscode-uri"; -import Parser, { Edit, Point, SyntaxNode } from "web-tree-sitter"; +import Parser, { Edit, Point, Node } from "web-tree-sitter"; import { ElmWorkspaceMatcher } from "../util/elmWorkspaceMatcher"; import { Position, @@ -28,11 +28,11 @@ export class ASTProvider { private treeChangeEvent = new Emitter<{ sourceFile: ISourceFile; - declaration?: SyntaxNode; + declaration?: Node; }>(); readonly onTreeChange: Event<{ sourceFile: ISourceFile; - declaration?: SyntaxNode; + declaration?: Node; }> = this.treeChangeEvent.event; private treeDeleteEvent = new Emitter<{ uri: string }>(); @@ -132,7 +132,7 @@ export class ASTProvider { hasContentChanges ? tree : undefined, ); - let changedDeclaration: SyntaxNode | undefined; + let changedDeclaration: Node | undefined; tree ?.getChangedRanges(newTree) diff --git a/src/common/providers/codeAction/addMissingRecordFieldCodeAction.ts b/src/common/providers/codeAction/addMissingRecordFieldCodeAction.ts index 23738330..745f506d 100644 --- a/src/common/providers/codeAction/addMissingRecordFieldCodeAction.ts +++ b/src/common/providers/codeAction/addMissingRecordFieldCodeAction.ts @@ -1,5 +1,5 @@ import { Range, TextEdit } from "vscode-languageserver"; -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; import { CodeActionProvider, ICodeAction } from ".."; import { ISourceFile } from "../../../compiler/forest"; import { getSpaces } from "../../util/refactorEditUtils"; @@ -97,7 +97,7 @@ function getEdits( function createFields( fields: [string, Type][], - targetRecord: SyntaxNode, + targetRecord: Node, checker: TypeChecker, sourceFile: ISourceFile, ): { [uri: string]: TextEdit[] } { diff --git a/src/common/providers/codeAction/addNewFunctionParameter.ts b/src/common/providers/codeAction/addNewFunctionParameter.ts index 914d9106..c8b0294a 100644 --- a/src/common/providers/codeAction/addNewFunctionParameter.ts +++ b/src/common/providers/codeAction/addNewFunctionParameter.ts @@ -3,7 +3,7 @@ import { TreeUtils } from "../../util/treeUtils"; import { Diagnostics } from "../../../compiler/diagnostics"; import { CodeActionProvider, ICodeAction } from "../codeActionProvider"; import { ICodeActionParams } from "../paramsExtensions"; -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; const errorCodes = [Diagnostics.MissingValue.code]; const fixId = "add_new_function_parameter"; @@ -40,8 +40,8 @@ function getActions( } function getActionsForValueDeclaration( - valueDeclaration: SyntaxNode, - nodeAtPosition: SyntaxNode, + valueDeclaration: Node, + nodeAtPosition: Node, params: ICodeActionParams, ): CodeAction | undefined { const lastFunctionParameter = valueDeclaration?.firstChild?.lastChild; @@ -76,8 +76,8 @@ function getActionsForValueDeclaration( function getEditsForSignatureUpdate( params: ICodeActionParams, - nodeAtPosition: SyntaxNode, - valueDeclaration: SyntaxNode, + nodeAtPosition: Node, + valueDeclaration: Node, ): TextEdit[] { const typeAnnotation = TreeUtils.getTypeAnnotation(valueDeclaration); const lastParameterType = diff --git a/src/common/providers/codeAction/extractFunctionCodeAction.ts b/src/common/providers/codeAction/extractFunctionCodeAction.ts index 8dd25dc5..928b34f3 100644 --- a/src/common/providers/codeAction/extractFunctionCodeAction.ts +++ b/src/common/providers/codeAction/extractFunctionCodeAction.ts @@ -1,5 +1,5 @@ import { CodeActionKind, Position, TextEdit } from "vscode-languageserver"; -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; import { RefactorEditUtils } from "../../util/refactorEditUtils"; import { TreeUtils } from "../../util/treeUtils"; import { TFunction } from "../../../compiler/typeInference"; @@ -87,7 +87,7 @@ CodeActionProvider.registerRefactorAction(refactorName, { line: rootNode.endPosition.row, character: 0, }; - let targetScope: SyntaxNode; + let targetScope: Node; let addTypeAnnotation = true; switch (actionName) { @@ -128,7 +128,7 @@ CodeActionProvider.registerRefactorAction(refactorName, { break; } - const args: SyntaxNode[] = []; + const args: Node[] = []; const nodeParent = node.parent; const imports = checker.getAllImports(params.sourceFile); @@ -136,6 +136,7 @@ CodeActionProvider.registerRefactorAction(refactorName, { // Get the list of references that won't be visible node .descendantsOfType(["value_expr", "record_base_identifier"]) + .filter((val) => val !== null) .forEach((val) => { if (args.find((arg) => arg.text === val.text)) { return; @@ -152,7 +153,7 @@ CodeActionProvider.registerRefactorAction(refactorName, { } // If we find it in the scope we are extracting, it should not be a arg - let scope: SyntaxNode | null = val; + let scope: Node | null = val; while (scope && scope.id !== nodeParent?.id) { if (params.sourceFile.symbolLinks?.get(scope)?.get(val.text)) { return; diff --git a/src/common/providers/codeAction/extractTypeAliasCodeAction.ts b/src/common/providers/codeAction/extractTypeAliasCodeAction.ts index e312f68b..1d82c878 100644 --- a/src/common/providers/codeAction/extractTypeAliasCodeAction.ts +++ b/src/common/providers/codeAction/extractTypeAliasCodeAction.ts @@ -1,5 +1,5 @@ import { CodeActionKind, Position, TextEdit } from "vscode-languageserver"; -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; import { RefactorEditUtils } from "../../util/refactorEditUtils"; import { TreeUtils } from "../../util/treeUtils"; import { @@ -118,7 +118,7 @@ CodeActionProvider.registerRefactorAction(refactorName, { ): IRefactorEdit => { const edits: TextEdit[] = []; - const nodes: SyntaxNode[] = []; + const nodes: Node[] = []; if (action === "extract_type_alias_partial_type_expr") { const startNode = TreeUtils.getNamedDescendantForPosition( params.sourceFile.tree.rootNode, diff --git a/src/common/providers/codeAction/importCodeAction.ts b/src/common/providers/codeAction/importCodeAction.ts index cad88093..26435749 100644 --- a/src/common/providers/codeAction/importCodeAction.ts +++ b/src/common/providers/codeAction/importCodeAction.ts @@ -1,6 +1,6 @@ import { CodeAction, TextEdit } from "vscode-languageserver"; import { Range } from "vscode-languageserver-textdocument"; -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; import { ISourceFile } from "../../../compiler/forest"; import { ImportUtils, IPossibleImport } from "../../util/importUtils"; import { RefactorEditUtils } from "../../util/refactorEditUtils"; @@ -149,7 +149,7 @@ function getEditFromPossibleImport( } function getValueToImport( - valueNode: SyntaxNode, + valueNode: Node, possibleImport: IPossibleImport, ): string | undefined { return valueNode.type !== "upper_case_qid" && valueNode.type !== "value_qid" @@ -157,7 +157,7 @@ function getValueToImport( : undefined; } -function getTargetModule(valueNode: SyntaxNode): string { +function getTargetModule(valueNode: Node): string { return valueNode.namedChildren .slice(0, valueNode.namedChildren.length - 2) // Dots are also namedNodes .map((a) => a.text) diff --git a/src/common/providers/codeLensProvider.ts b/src/common/providers/codeLensProvider.ts index 08f2c7b5..3a2aed4c 100644 --- a/src/common/providers/codeLensProvider.ts +++ b/src/common/providers/codeLensProvider.ts @@ -9,7 +9,7 @@ import { Range, } from "vscode-languageserver"; import { URI } from "vscode-uri"; -import { SyntaxNode, Tree } from "web-tree-sitter"; +import { Node, Tree } from "web-tree-sitter"; import { IProgram } from "../../compiler/program"; import { ISourceFile } from "../../compiler/forest"; import { ElmWorkspaceMatcher } from "../util/elmWorkspaceMatcher"; @@ -174,8 +174,8 @@ export class CodeLensProvider { }; private createExposingCodeLens( - node: SyntaxNode, - nameNode: SyntaxNode, + node: Node, + nameNode: Node, uri: string, isFunctionOrPort: boolean, ): ICodeLens { @@ -193,10 +193,7 @@ export class CodeLensProvider { }; } - private createReferenceCodeLens( - placementNode: SyntaxNode, - uri: string, - ): ICodeLens { + private createReferenceCodeLens(placementNode: Node, uri: string): ICodeLens { return { range: Range.create( Position.create( diff --git a/src/common/providers/completionProvider.ts b/src/common/providers/completionProvider.ts index fedef668..c6bf94ec 100644 --- a/src/common/providers/completionProvider.ts +++ b/src/common/providers/completionProvider.ts @@ -12,7 +12,7 @@ import { TextEdit, } from "vscode-languageserver"; import { URI } from "vscode-uri"; -import { SyntaxNode, Tree } from "web-tree-sitter"; +import { Node, Tree } from "web-tree-sitter"; import { IProgram } from "../../compiler/program"; import { ISourceFile } from "../../compiler/forest"; import { comparePosition, PositionUtil } from "../positionUtil"; @@ -473,7 +473,7 @@ export class CompletionProvider { private getExposedFromModule( program: IProgram, sourceFile: ISourceFile, - exposingListNode: SyntaxNode, + exposingListNode: Node, range: Range, ): CompletionItem[] | undefined { // Skip as clause to always get Module Name @@ -755,7 +755,7 @@ export class CompletionProvider { } private getRecordCompletions( - node: SyntaxNode, + node: Node, sourceFile: ISourceFile, range: Range, program: IProgram, @@ -847,7 +847,7 @@ export class CompletionProvider { private getRecordCompletionsUsingInference( checker: TypeChecker, - targetNode: SyntaxNode, + targetNode: Node, replaceRange: Range, ): CompletionItem[] { const result: CompletionItem[] = []; @@ -972,7 +972,7 @@ export class CompletionProvider { private findDefinitionsForScope( checker: TypeChecker, - node: SyntaxNode, + node: Node, sourceFile: ISourceFile, range: Range, ): CompletionItem[] { @@ -1190,7 +1190,7 @@ export class CompletionProvider { } private getSubmodulesOrValues( - node: SyntaxNode, + node: Node, sourceFile: ISourceFile, program: IProgram, range: Range, diff --git a/src/common/providers/definitionProvider.ts b/src/common/providers/definitionProvider.ts index 87160e4b..f0243558 100644 --- a/src/common/providers/definitionProvider.ts +++ b/src/common/providers/definitionProvider.ts @@ -8,7 +8,7 @@ import { TextDocumentPositionParams, } from "vscode-languageserver"; import { URI } from "vscode-uri"; -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; import { ElmWorkspaceMatcher } from "../util/elmWorkspaceMatcher"; import { TreeUtils } from "../util/treeUtils"; import { ITextDocumentPositionParams } from "./paramsExtensions"; @@ -59,7 +59,7 @@ export class DefinitionProvider { }; private createLocationFromDefinition( - definitionNode: SyntaxNode | undefined, + definitionNode: Node | undefined, uri: string, ): Location | undefined { if (definitionNode) { diff --git a/src/common/providers/diagnostics/elmLsDiagnostics.ts b/src/common/providers/diagnostics/elmLsDiagnostics.ts index c5999f70..9bdbd9f0 100644 --- a/src/common/providers/diagnostics/elmLsDiagnostics.ts +++ b/src/common/providers/diagnostics/elmLsDiagnostics.ts @@ -13,7 +13,7 @@ import { Parser, Query, QueryResult, - SyntaxNode, + Node, Tree, } from "web-tree-sitter"; import { IProgram } from "../../../compiler/program"; @@ -654,7 +654,7 @@ export class ElmLsDiagnostics { const patternMatches = this.patternsQuery.matches(tree.rootNode); - const scopeCache = new SyntaxNodeMap(); + const scopeCache = new SyntaxNodeMap(); patternMatches .filter(Utils.notUndefined) @@ -1075,7 +1075,7 @@ export class ElmLsDiagnostics { return diagnostics; } - private getNodeRange(node: SyntaxNode): Range { + private getNodeRange(node: Node): Range { const end = PositionUtil.FROM_TS_POSITION(node.endPosition).toVSPosition(); return { start: PositionUtil.FROM_TS_POSITION(node.startPosition).toVSPosition(), diff --git a/src/common/providers/documentSymbolProvider.ts b/src/common/providers/documentSymbolProvider.ts index 96c82801..3e97420f 100644 --- a/src/common/providers/documentSymbolProvider.ts +++ b/src/common/providers/documentSymbolProvider.ts @@ -7,7 +7,7 @@ import { SymbolInformation, } from "vscode-languageserver"; import { URI } from "vscode-uri"; -import { SyntaxNode, Tree } from "web-tree-sitter"; +import { Node, Tree } from "web-tree-sitter"; import { ElmWorkspaceMatcher } from "../util/elmWorkspaceMatcher"; import { SymbolInformationTranslator } from "../util/symbolTranslator"; import { ThrottledCancellationToken } from "../cancellation"; @@ -44,7 +44,7 @@ export class DocumentSymbolProvider { ? new ThrottledCancellationToken(token) : undefined; - const traverse: (node: SyntaxNode) => void = (node: SyntaxNode): void => { + const traverse: (node: Node) => void = (node: Node): void => { cancellationToken?.throwIfCancellationRequested(); const symbolInformation = diff --git a/src/common/providers/findTestsProvider.ts b/src/common/providers/findTestsProvider.ts index dc9ee6f3..877d8a93 100644 --- a/src/common/providers/findTestsProvider.ts +++ b/src/common/providers/findTestsProvider.ts @@ -1,6 +1,6 @@ import { container } from "tsyringe"; import { Connection, ResponseError } from "vscode-languageserver"; -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; import { ISourceFile } from "../../compiler/forest"; import { IProgram, Program } from "../../compiler/program"; import { TypeChecker } from "../../compiler/typeChecker"; @@ -106,7 +106,7 @@ function rootSuite( // export for testing export function findTestFunctionCall( - node: SyntaxNode, + node: Node, typeChecker: TypeChecker, ): EFunctionCallExpr | undefined { const letIn = findChildExpr("LetInExpr", node); @@ -214,7 +214,7 @@ const typeByNodeType: Map = new Map([ function findExpr( key: K, - node: SyntaxNode | undefined, + node: Node | undefined, ): ExpressionNodeTypes[K] | undefined { if (!node) { return undefined; @@ -231,7 +231,7 @@ function findExpr( function findChildExpr( key: K, - node: SyntaxNode | undefined, + node: Node | undefined, ): ExpressionNodeTypes[K] | undefined { if (!node) { return undefined; @@ -248,7 +248,7 @@ function findChildExpr( function findAllExprs( key: K, - node: SyntaxNode | undefined, + node: Node | undefined, ): ExpressionNodeTypes[K][] | undefined { if (!node) { return undefined; diff --git a/src/common/providers/foldingProvider.ts b/src/common/providers/foldingProvider.ts index 3e7eb5c3..91469f2c 100644 --- a/src/common/providers/foldingProvider.ts +++ b/src/common/providers/foldingProvider.ts @@ -6,7 +6,7 @@ import { FoldingRangeParams, } from "vscode-languageserver"; import { URI } from "vscode-uri"; -import { SyntaxNode, Tree } from "web-tree-sitter"; +import { Node, Tree } from "web-tree-sitter"; import { ElmWorkspaceMatcher } from "../util/elmWorkspaceMatcher"; import { IFoldingRangeParams } from "./paramsExtensions"; @@ -36,9 +36,9 @@ export class FoldingRangeProvider { const folds: FoldingRange[] = []; const tree: Tree = param.sourceFile.tree; - const findLastIdenticalNamedSibling: (node: SyntaxNode) => SyntaxNode = ( - node: SyntaxNode, - ): SyntaxNode => { + const findLastIdenticalNamedSibling: (node: Node) => Node = ( + node: Node, + ): Node => { // eslint-disable-next-line no-constant-condition while (true) { const nextSibling = node.nextNamedSibling; diff --git a/src/common/providers/renameProvider.ts b/src/common/providers/renameProvider.ts index d977bb3b..e7df563a 100644 --- a/src/common/providers/renameProvider.ts +++ b/src/common/providers/renameProvider.ts @@ -12,7 +12,7 @@ import { WorkspaceEdit, } from "vscode-languageserver"; import { URI } from "vscode-uri"; -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; import { IProgram } from "../../compiler/program"; import { ElmWorkspaceMatcher } from "../util/elmWorkspaceMatcher"; import { RenameUtils } from "../util/renameUtils"; @@ -126,8 +126,8 @@ export class RenameProvider { public static getRenameEdits( affectedNodes: | { - originalNode: SyntaxNode; - references: { node: SyntaxNode; uri: string }[]; + originalNode: Node; + references: { node: Node; uri: string }[]; } | undefined, newName: string, @@ -189,9 +189,9 @@ export class RenameProvider { private createModuleDeclarationRenameChange( affectedNodes: | { - originalNode: SyntaxNode; + originalNode: Node; references: { - node: SyntaxNode; + node: Node; uri: string; }[]; } @@ -223,8 +223,8 @@ export class RenameProvider { newName: string, affectedNodes: | { - originalNode: SyntaxNode; - references: { node: SyntaxNode; uri: string }[]; + originalNode: Node; + references: { node: Node; uri: string }[]; } | undefined, ): string { diff --git a/src/common/providers/selectionRangeProvider.ts b/src/common/providers/selectionRangeProvider.ts index bcc038cb..6acb7219 100644 --- a/src/common/providers/selectionRangeProvider.ts +++ b/src/common/providers/selectionRangeProvider.ts @@ -7,7 +7,7 @@ import { SelectionRangeParams, } from "vscode-languageserver"; import { URI } from "vscode-uri"; -import { SyntaxNode, Tree } from "web-tree-sitter"; +import { Node, Tree } from "web-tree-sitter"; import { PositionUtil } from "../positionUtil"; import { ElmWorkspaceMatcher } from "../util/elmWorkspaceMatcher"; import { TreeUtils } from "../util/treeUtils"; @@ -59,7 +59,7 @@ export class SelectionRangeProvider { }; private getParentNode( - node: SyntaxNode, + node: Node, previousRange: Range, ): SelectionRange | undefined { if (node.parent) { diff --git a/src/common/providers/workspaceSymbolProvider.ts b/src/common/providers/workspaceSymbolProvider.ts index 3deac869..b8b7a32f 100644 --- a/src/common/providers/workspaceSymbolProvider.ts +++ b/src/common/providers/workspaceSymbolProvider.ts @@ -4,7 +4,7 @@ import { SymbolInformation, WorkspaceSymbolParams, } from "vscode-languageserver"; -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; import { IProgram } from "../../compiler/program"; import { SymbolInformationTranslator } from "../util/symbolTranslator"; @@ -32,9 +32,7 @@ export class WorkspaceSymbolProvider { if (!sourceFile.writeable) { return; } - const traverse: (node: SyntaxNode) => void = ( - node: SyntaxNode, - ): void => { + const traverse: (node: Node) => void = (node: Node): void => { if (this.isPatternInSymbol(param.query, node.text)) { const symbolInformation = SymbolInformationTranslator.translateNodeToSymbolInformation( diff --git a/src/common/util/hintHelper.ts b/src/common/util/hintHelper.ts index cdfdf40b..69ca2381 100644 --- a/src/common/util/hintHelper.ts +++ b/src/common/util/hintHelper.ts @@ -1,9 +1,9 @@ -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; import { TreeUtils } from "./treeUtils"; export class HintHelper { public static createHint( - node: SyntaxNode | undefined, + node: Node | undefined, typeString?: string, ): string | undefined { if (!node) { @@ -43,7 +43,7 @@ export class HintHelper { } public static createHintFromFunctionParameter( - node: SyntaxNode | undefined, + node: Node | undefined, typeString?: string, ): string { const annotation = TreeUtils.getTypeOrTypeAliasOfFunctionParameter(node); @@ -72,7 +72,7 @@ export class HintHelper { } public static createHintFromDefinitionInLet( - declaration: SyntaxNode | undefined, + declaration: Node | undefined, typeString?: string, ): string | undefined { if (declaration) { @@ -95,7 +95,7 @@ export class HintHelper { } } - public static createHintFromFieldType(node: SyntaxNode): string { + public static createHintFromFieldType(node: Node): string { const typeAlias = TreeUtils.findParentOfType( "type_alias_declaration", node, @@ -127,7 +127,7 @@ export class HintHelper { } private static createHintFromDefinition( - declaration: SyntaxNode | undefined, + declaration: Node | undefined, typeString?: string, ): string | undefined { if (!declaration) { @@ -199,7 +199,7 @@ export class HintHelper { } private static createHintFromModule( - moduleNode: SyntaxNode | undefined, + moduleNode: Node | undefined, ): string | undefined { if (moduleNode) { let comment = ""; diff --git a/src/common/util/importUtils.ts b/src/common/util/importUtils.ts index 7dfc95c9..10139208 100644 --- a/src/common/util/importUtils.ts +++ b/src/common/util/importUtils.ts @@ -1,14 +1,14 @@ import { comparePackageRanking } from "../providers/ranking"; import { ISourceFile } from "../../compiler/forest"; import { NodeType } from "./treeUtils"; -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; import { IProgram } from "../../compiler/program"; export interface IPossibleImport { module: string; value: string; type: NodeType; - node: SyntaxNode; + node: Node; valueToImport?: string; package?: string; } diff --git a/src/common/util/refactorEditUtils.ts b/src/common/util/refactorEditUtils.ts index a4fd9f6e..f06f1290 100644 --- a/src/common/util/refactorEditUtils.ts +++ b/src/common/util/refactorEditUtils.ts @@ -1,10 +1,10 @@ import { Position, Range, TextEdit } from "vscode-languageserver"; -import { SyntaxNode, Tree } from "web-tree-sitter"; +import { Node, Tree } from "web-tree-sitter"; import { TreeUtils } from "./treeUtils"; export class RefactorEditUtils { public static findLineNumberAfterCurrentFunction( - nodeAtPosition: SyntaxNode, + nodeAtPosition: Node, ): number | undefined { if (!nodeAtPosition.parent) { return undefined; @@ -18,7 +18,7 @@ export class RefactorEditUtils { } public static findLineNumberBeforeCurrentFunction( - nodeAtPosition: SyntaxNode, + nodeAtPosition: Node, ): number | undefined { if (!nodeAtPosition.parent) { return undefined; @@ -259,7 +259,7 @@ export class RefactorEditUtils { } public static changeQualifiedReferenceModule( - node: SyntaxNode, + node: Node, newModuleName: string, ): TextEdit | undefined { if (node.parent && node.parent.type === "value_qid") { @@ -286,9 +286,7 @@ export class RefactorEditUtils { } } - public static removeQualifiedReference( - node: SyntaxNode, - ): TextEdit | undefined { + public static removeQualifiedReference(node: Node): TextEdit | undefined { if (node.parent && node.parent.type === "value_qid") { const moduleNode = TreeUtils.findFirstNamedChildOfType( "upper_case_identifier", @@ -380,7 +378,7 @@ export class RefactorEditUtils { } } - public static removeRecordPatternValue(pattern: SyntaxNode): TextEdit { + public static removeRecordPatternValue(pattern: Node): TextEdit { let startPosition = pattern.startPosition; let endPosition = pattern.endPosition; @@ -404,9 +402,7 @@ export class RefactorEditUtils { ); } - public static removeFunction( - nodeAtPosition: SyntaxNode, - ): TextEdit | undefined { + public static removeFunction(nodeAtPosition: Node): TextEdit | undefined { const valueDeclaration = TreeUtils.findParentOfType( "value_declaration", nodeAtPosition, @@ -439,7 +435,7 @@ export class RefactorEditUtils { } } - public static removeTypeAlias(node: SyntaxNode | null): TextEdit | undefined { + public static removeTypeAlias(node: Node | null): TextEdit | undefined { if (!node) { return undefined; } @@ -464,9 +460,7 @@ export class RefactorEditUtils { ); } - public static removeTypeValue( - nodeAtPosition: SyntaxNode, - ): TextEdit | undefined { + public static removeTypeValue(nodeAtPosition: Node): TextEdit | undefined { const unionVariants = TreeUtils.findParentOfType( "type_declaration", nodeAtPosition, @@ -506,7 +500,7 @@ export class RefactorEditUtils { ); } - public static removeType(node: SyntaxNode | null): TextEdit | undefined { + public static removeType(node: Node | null): TextEdit | undefined { if (!node) { return undefined; } @@ -532,7 +526,7 @@ export class RefactorEditUtils { } public static addUnionVariant( - typeDeclaration: SyntaxNode, + typeDeclaration: Node, name: string, params: string[], ): TextEdit | undefined { @@ -557,7 +551,7 @@ export class RefactorEditUtils { } private static removeValueFromExposingList( - exposedNodes: SyntaxNode[], + exposedNodes: Node[], valueName: string, forceRemoveLastComma = false, ): TextEdit | undefined { diff --git a/src/common/util/referenceNode.ts b/src/common/util/referenceNode.ts index 78252353..6b6ffe96 100644 --- a/src/common/util/referenceNode.ts +++ b/src/common/util/referenceNode.ts @@ -1,8 +1,8 @@ -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; import { NodeType } from "./treeUtils"; export interface IReferenceNode { - node: SyntaxNode; + node: Node; nodeType: NodeType; uri: string; } diff --git a/src/common/util/renameUtils.ts b/src/common/util/renameUtils.ts index b4875401..f407335a 100644 --- a/src/common/util/renameUtils.ts +++ b/src/common/util/renameUtils.ts @@ -1,6 +1,6 @@ import { IProgram } from "../../compiler/program"; import { Position, ResponseError } from "vscode-languageserver"; -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; import { References } from "../../compiler/references"; import { TreeUtils } from "./treeUtils"; @@ -11,9 +11,9 @@ export class RenameUtils { position: Position, ): | { - originalNode: SyntaxNode; + originalNode: Node; references: { - node: SyntaxNode; + node: Node; uri: string; }[]; } diff --git a/src/common/util/symbolTranslator.ts b/src/common/util/symbolTranslator.ts index f8b85869..4acf9f73 100644 --- a/src/common/util/symbolTranslator.ts +++ b/src/common/util/symbolTranslator.ts @@ -4,12 +4,12 @@ import { SymbolInformation, SymbolKind, } from "vscode-languageserver"; -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; export class SymbolInformationTranslator { public static translateNodeToSymbolInformation( uri: string, - node: SyntaxNode, + node: Node, ): SymbolInformation | undefined { switch (node.type) { case "value_declaration": @@ -78,7 +78,7 @@ export class SymbolInformationTranslator { private static createSymbolInformation( name: string, - node: SyntaxNode, + node: Node, symbolKind: SymbolKind, uri: string, ): SymbolInformation { diff --git a/src/common/util/treeUtils.ts b/src/common/util/treeUtils.ts index a94ff60b..e81cb69a 100644 --- a/src/common/util/treeUtils.ts +++ b/src/common/util/treeUtils.ts @@ -1,5 +1,5 @@ import { Position } from "vscode-languageserver"; -import { SyntaxNode, Tree } from "web-tree-sitter"; +import { Node, Tree } from "web-tree-sitter"; import { ISourceFile } from "../../compiler/forest"; import { comparePosition, positionEquals } from "../positionUtil"; import { TRecord, Type } from "../../compiler/typeInference"; @@ -29,21 +29,21 @@ export type NodeType = const functionNameRegex = new RegExp("[a-zA-Z0-9_]+"); export class TreeUtils { - public static getModuleNameNode(tree: Tree): SyntaxNode | undefined { - const moduleDeclaration: SyntaxNode | undefined = + public static getModuleNameNode(tree: Tree): Node | undefined { + const moduleDeclaration: Node | undefined = this.findModuleDeclaration(tree); return moduleDeclaration?.childForFieldName("name") ?? undefined; } - public static getModuleNameCommentNode(tree: Tree): SyntaxNode | undefined { - const moduleDeclaration: SyntaxNode | undefined = + public static getModuleNameCommentNode(tree: Tree): Node | undefined { + const moduleDeclaration: Node | undefined = this.findModuleDeclaration(tree); return moduleDeclaration?.nextNamedSibling?.type === "block_comment" ? moduleDeclaration.nextNamedSibling : undefined; } - public static getModuleExposingListNodes(tree: Tree): SyntaxNode[] { + public static getModuleExposingListNodes(tree: Tree): Node[] { const moduleNode = TreeUtils.findModuleDeclaration(tree); if (moduleNode) { @@ -57,15 +57,15 @@ export class TreeUtils { public static findFirstNamedChildOfType( type: string, - node: SyntaxNode, - ): SyntaxNode | undefined { + node: Node, + ): Node | undefined { return node.children.find((child) => child.type === type); } public static findAllNamedChildrenOfType( type: string | string[], - node: SyntaxNode, - ): SyntaxNode[] | undefined { + node: Node, + ): Node[] | undefined { const result = Array.isArray(type) ? node.children.filter((child) => type.includes(child.type)) : node.children.filter((child) => child.type === type); @@ -74,9 +74,9 @@ export class TreeUtils { } public static findExposedFunctionNode( - node: SyntaxNode, + node: Node, functionName: string, - ): SyntaxNode | undefined { + ): Node | undefined { if (node) { const exposingList = this.findFirstNamedChildOfType( "exposing_list", @@ -119,9 +119,9 @@ export class TreeUtils { } public static findExposedTypeOrTypeAliasNode( - node: SyntaxNode, + node: Node, typeName: string, - ): SyntaxNode | undefined { + ): Node | undefined { if (node) { const exposingList = this.findFirstNamedChildOfType( "exposing_list", @@ -180,7 +180,7 @@ export class TreeUtils { tree: Tree, unionConstructorName: string, moduleNamePrefix?: string, - ): SyntaxNode[] | undefined { + ): Node[] | undefined { const upperCaseQid = TreeUtils.descendantsOfType( tree.rootNode, "upper_case_qid", @@ -202,7 +202,7 @@ export class TreeUtils { public static findOperator( sourceFile: ISourceFile, operatorName: string, - ): SyntaxNode | undefined { + ): Node | undefined { const rootSymbols = sourceFile.symbolLinks?.get(sourceFile.tree.rootNode); const operatorNode = rootSymbols?.get(operatorName)?.node; @@ -224,7 +224,7 @@ export class TreeUtils { public static findTypeDeclaration( tree: Tree, typeName: string, - ): SyntaxNode | undefined { + ): Node | undefined { const types = this.findAllTypeDeclarations(tree); if (types) { return types.find( @@ -236,13 +236,13 @@ export class TreeUtils { } } - public static findModuleDeclaration(tree: Tree): SyntaxNode | undefined { + public static findModuleDeclaration(tree: Tree): Node | undefined { return tree.rootNode.childForFieldName("moduleDeclaration") ?? undefined; } public static findAllTopLevelFunctionDeclarations( tree: Tree, - ): SyntaxNode[] | undefined { + ): Node[] | undefined { const result = tree.rootNode.children.filter( (a) => a.type === "value_declaration", ); @@ -250,8 +250,8 @@ export class TreeUtils { } public static getFunctionNameNodeFromDefinition( - node: SyntaxNode, - ): SyntaxNode | undefined { + node: Node, + ): Node | undefined { if (node.type === "lower_case_identifier") { return node; } @@ -265,19 +265,19 @@ export class TreeUtils { } public static getTypeOrTypeAliasOrPortNameNodeFromDefinition( - node: SyntaxNode, - ): SyntaxNode | undefined { + node: Node, + ): Node | undefined { return node.childForFieldName("name") ?? undefined; } - public static isTypeUsage(upperCaseQid: SyntaxNode): boolean { + public static isTypeUsage(upperCaseQid: Node): boolean { return ( !!TreeUtils.findParentOfType("type_ref", upperCaseQid) || upperCaseQid.parent?.type === "exposed_type" ); } - public static isConstructorUsage(upperCaseQid: SyntaxNode): boolean { + public static isConstructorUsage(upperCaseQid: Node): boolean { return upperCaseQid.parent?.type === "value_expr"; } @@ -285,7 +285,7 @@ export class TreeUtils { tree: Tree, typeOrTypeAliasName: string, nodeType: NodeType, - ): SyntaxNode[] { + ): Node[] { const upperCaseQids = TreeUtils.descendantsOfType( tree.rootNode, "upper_case_qid", @@ -303,7 +303,7 @@ export class TreeUtils { }); } - public static findAllTypeDeclarations(tree: Tree): SyntaxNode[] | undefined { + public static findAllTypeDeclarations(tree: Tree): Node[] | undefined { return this.findAllNamedChildrenOfType("type_declaration", tree.rootNode); } @@ -313,7 +313,7 @@ export class TreeUtils { public static findImportClauseByName( tree: Tree, moduleName: string, - ): SyntaxNode | undefined { + ): Node | undefined { const allImports = this.findAllImportClauseNodes(tree); if (allImports) { return allImports.find( @@ -326,8 +326,8 @@ export class TreeUtils { } public static getTypeOrTypeAliasOfFunctionParameter( - node: SyntaxNode | undefined, - ): SyntaxNode | undefined { + node: Node | undefined, + ): Node | undefined { if ( node && node.parent && @@ -359,8 +359,8 @@ export class TreeUtils { } public static getReturnTypeOrTypeAliasOfFunctionDefinition( - node: SyntaxNode | undefined, - ): SyntaxNode | undefined { + node: Node | undefined, + ): Node | undefined { if (node && node.previousNamedSibling?.type === "type_annotation") { const typeAnnotationNodes = TreeUtils.descendantsOfType( node.previousNamedSibling, @@ -374,7 +374,7 @@ export class TreeUtils { } public static getRecordTypeOfFunctionRecordParameter( - node: SyntaxNode | undefined, + node: Node | undefined, program: IProgram, ): TRecord | undefined { const checker = program.getTypeChecker(); @@ -403,10 +403,10 @@ export class TreeUtils { } public static getTypeAliasOfRecordField( - node: SyntaxNode | undefined, + node: Node | undefined, sourceFile: ISourceFile, program: IProgram, - ): SyntaxNode | undefined { + ): Node | undefined { const fieldName = node?.parent?.firstNamedChild?.text; let recordType = TreeUtils.getTypeAliasOfRecord(node, sourceFile, program); @@ -460,12 +460,12 @@ export class TreeUtils { } public static getTypeAliasOfRecord( - node: SyntaxNode | undefined, + node: Node | undefined, sourceFile: ISourceFile, program: IProgram, - ): SyntaxNode | undefined { + ): Node | undefined { if (node?.parent?.parent) { - let type: SyntaxNode | undefined | null = + let type: Node | undefined | null = TreeUtils.findFirstNamedChildOfType( "record_base_identifier", node.parent.parent, @@ -543,7 +543,7 @@ export class TreeUtils { } public static getAllFieldsFromTypeAlias( - node: SyntaxNode | undefined, + node: Node | undefined, ): { field: string; type: string }[] | undefined { const result: { field: string; type: string }[] = []; if (node) { @@ -567,17 +567,14 @@ export class TreeUtils { return result.length === 0 ? undefined : result; } - public static descendantsOfType( - node: SyntaxNode, - type: string, - ): SyntaxNode[] { + public static descendantsOfType(node: Node, type: string): Node[] { return node.descendantsOfType(type); } public static getNamedDescendantForPosition( - node: SyntaxNode, + node: Node, position: Position, - ): SyntaxNode { + ): Node { const previousCharColumn = position.character === 0 ? 0 : position.character - 1; const charBeforeCursor = node.text @@ -603,10 +600,7 @@ export class TreeUtils { } } - public static getDescendantForPosition( - node: SyntaxNode, - position: Position, - ): SyntaxNode { + public static getDescendantForPosition(node: Node, position: Position): Node { const previousCharColumn = position.character === 0 ? 0 : position.character - 1; const charBeforeCursor = node.text @@ -635,7 +629,7 @@ export class TreeUtils { public static getNamedDescendantForRange( sourceFile: ISourceFile, range: Range, - ): SyntaxNode { + ): Node { if (positionEquals(range.start, range.end)) { return this.getNamedDescendantForPosition(sourceFile.tree.rootNode, { character: range.start.character, @@ -658,7 +652,7 @@ export class TreeUtils { public static getDescendantForRange( sourceFile: ISourceFile, range: Range, - ): SyntaxNode { + ): Node { if (positionEquals(range.start, range.end)) { return this.getDescendantForPosition(sourceFile.tree.rootNode, { character: range.start.character, @@ -679,17 +673,17 @@ export class TreeUtils { } public static findPreviousNode( - node: SyntaxNode, + node: Node, position: Position, - ): SyntaxNode | undefined { - function nodeHasTokens(n: SyntaxNode): boolean { + ): Node | undefined { + function nodeHasTokens(n: Node): boolean { return n.endIndex - n.startIndex !== 0; } function findRightmostChildWithTokens( - childrenList: SyntaxNode[], + childrenList: Node[], startIndex: number, - ): SyntaxNode | undefined { + ): Node | undefined { for (let i = startIndex - 1; i >= 0; i--) { if (nodeHasTokens(childrenList[i])) { return childrenList[i]; @@ -697,7 +691,7 @@ export class TreeUtils { } } - function findRightmostNode(n: SyntaxNode): SyntaxNode | undefined { + function findRightmostNode(n: Node): Node | undefined { if (n.children.length === 0) { return n; } @@ -743,9 +737,9 @@ export class TreeUtils { } public static getNamedDescendantForLineBeforePosition( - node: SyntaxNode, + node: Node, position: Position, - ): SyntaxNode { + ): Node { const previousLine = position.line === 0 ? 0 : position.line - 1; return node.namedDescendantForPosition({ @@ -755,9 +749,9 @@ export class TreeUtils { } public static getNamedDescendantForLineAfterPosition( - node: SyntaxNode, + node: Node, position: Position, - ): SyntaxNode { + ): Node { const followingLine = position.line + 1; return node.namedDescendantForPosition({ @@ -768,9 +762,9 @@ export class TreeUtils { public static findParentOfType( typeToLookFor: string, - node: SyntaxNode, + node: Node, topLevel = false, - ): SyntaxNode | undefined { + ): Node | undefined { if ( node.type === typeToLookFor && (!topLevel || node.parent?.type === "file") @@ -782,14 +776,14 @@ export class TreeUtils { } } - public static getLastImportNode(tree: Tree): SyntaxNode | undefined { + public static getLastImportNode(tree: Tree): Node | undefined { const allImportNodes = this.findAllImportClauseNodes(tree); if (allImportNodes?.length) { return allImportNodes[allImportNodes.length - 1]; } } - public static isReferenceFullyQualified(node: SyntaxNode): boolean { + public static isReferenceFullyQualified(node: Node): boolean { return ( node.previousNamedSibling?.type === "dot" && node.previousNamedSibling?.previousNamedSibling?.type === @@ -797,9 +791,7 @@ export class TreeUtils { ); } - public static getTypeAnnotation( - valueDeclaration?: SyntaxNode, - ): SyntaxNode | undefined { + public static getTypeAnnotation(valueDeclaration?: Node): Node | undefined { if (valueDeclaration?.type !== "value_declaration") { return; } @@ -819,9 +811,7 @@ export class TreeUtils { } } - public static getValueDeclaration( - typeAnnotation?: SyntaxNode, - ): SyntaxNode | undefined { + public static getValueDeclaration(typeAnnotation?: Node): Node | undefined { if (typeAnnotation?.type !== "type_annotation") { return; } @@ -845,10 +835,7 @@ export class TreeUtils { * This gets a list of all ancestors of a type * in order from the closest declaration up to the top level declaration */ - public static getAllAncestorsOfType( - type: string, - node: SyntaxNode, - ): SyntaxNode[] { + public static getAllAncestorsOfType(type: string, node: Node): Node[] { const declarations = []; while (node.type !== "file") { @@ -869,7 +856,7 @@ export class TreeUtils { /** * @deprecated Should not be used due to performance. Use bindings instead */ - public static findAllImportClauseNodes(tree: Tree): SyntaxNode[] | undefined { + public static findAllImportClauseNodes(tree: Tree): Node[] | undefined { const result = tree.rootNode.children.filter( (a) => a.type === "import_clause", ); @@ -877,21 +864,21 @@ export class TreeUtils { return result.length === 0 ? undefined : result; } - public static isIdentifier(node: SyntaxNode): boolean { + public static isIdentifier(node: Node): boolean { return ( node.type === "lower_case_identifier" || node.type === "upper_case_identifier" ); } - public static isImport(node: SyntaxNode): boolean { + public static isImport(node: Node): boolean { return ( node.parent?.firstNamedChild?.type === "import" || node.parent?.parent?.firstNamedChild?.type === "import" ); } - public static nextNode(node: SyntaxNode): SyntaxNode | undefined { + public static nextNode(node: Node): Node | undefined { // Move up until we have a sibling while (!node.nextNamedSibling && node.parent) { node = node.parent; diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 61b01713..878c3391 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1,5 +1,5 @@ import { ISourceFile } from "./forest"; -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; import { MultiMap } from "../common/util/multiMap"; import { NodeType, TreeUtils } from "../common/util/treeUtils"; import { Utils } from "../common/util/utils"; @@ -16,11 +16,11 @@ export type IExposing = Map; export interface ISymbol { name: string; - node: SyntaxNode; + node: Node; type: NodeType; constructors?: { name: string; - node: SyntaxNode; + node: Node; type: "UnionConstructor" | "TypeAlias"; }[]; } @@ -30,10 +30,10 @@ export function bindTreeContainer(sourceFile: ISourceFile): void { return; } - const symbolLinks = new SyntaxNodeMap(); + const symbolLinks = new SyntaxNodeMap(); const nonShadowableNames = new Set(); let container: SymbolMap; - let parent: SyntaxNode; + let parent: Node; const treeCursor = sourceFile.tree.walk(); bind(); @@ -99,7 +99,7 @@ export function bindTreeContainer(sourceFile: ISourceFile): void { } } - function bindContainer(node: SyntaxNode): void { + function bindContainer(node: Node): void { const savedContainer = container; const savedParent = parent; @@ -118,7 +118,7 @@ export function bindTreeContainer(sourceFile: ISourceFile): void { parent = savedParent; } - function bindValueDeclaration(node: SyntaxNode): void { + function bindValueDeclaration(node: Node): void { // Bind the function name const functionDeclarationLeft = node.childForFieldName( "functionDeclarationLeft", @@ -155,7 +155,7 @@ export function bindTreeContainer(sourceFile: ISourceFile): void { bindContainer(node); } - function bindFunctionDeclarationLeft(node: SyntaxNode): void { + function bindFunctionDeclarationLeft(node: Node): void { node.descendantsOfType("lower_pattern").forEach((lowerPattern) => { container.set(lowerPattern.text, { name: lowerPattern.text, @@ -165,7 +165,7 @@ export function bindTreeContainer(sourceFile: ISourceFile): void { }); } - function bindTypeDeclaration(node: SyntaxNode): void { + function bindTypeDeclaration(node: Node): void { const unionVariants = TreeUtils.findAllNamedChildrenOfType("union_variant", node) ?.map((unionVariant) => { @@ -204,7 +204,7 @@ export function bindTreeContainer(sourceFile: ISourceFile): void { bindContainer(node); } - function bindTypeAliasDeclaration(node: SyntaxNode): void { + function bindTypeAliasDeclaration(node: Node): void { const name = node.childForFieldName("name"); if (name) { @@ -226,11 +226,11 @@ export function bindTreeContainer(sourceFile: ISourceFile): void { bindContainer(node); } - function bindLowerTypeName(node: SyntaxNode): void { + function bindLowerTypeName(node: Node): void { container.set(node.text, { name: node.text, node, type: "TypeVariable" }); } - function bindPortAnnotation(node: SyntaxNode): void { + function bindPortAnnotation(node: Node): void { // TODO: Use field const name = TreeUtils.findFirstNamedChildOfType( "lower_case_identifier", @@ -242,7 +242,7 @@ export function bindTreeContainer(sourceFile: ISourceFile): void { } } - function bindInfixDeclaration(node: SyntaxNode): void { + function bindInfixDeclaration(node: Node): void { const operator = node.childForFieldName("operator"); const name = node.lastNamedChild; if (operator && name) { @@ -255,7 +255,7 @@ export function bindTreeContainer(sourceFile: ISourceFile): void { } } - function bindPattern(node: SyntaxNode): void { + function bindPattern(node: Node): void { node.descendantsOfType("lower_pattern").forEach((lowerPattern) => { switch (parent.type) { case "anonymous_function_expr": @@ -280,7 +280,7 @@ export function bindTreeContainer(sourceFile: ISourceFile): void { Imports.getVirtualImports().forEach(bindImportClause); } - function bindImportClause(node: SyntaxNode): void { + function bindImportClause(node: Node): void { const asClause = node.childForFieldName("asClause"); let name; diff --git a/src/compiler/diagnostics.ts b/src/compiler/diagnostics.ts index 9b05e129..80f9e97b 100644 --- a/src/compiler/diagnostics.ts +++ b/src/compiler/diagnostics.ts @@ -4,7 +4,7 @@ import { DiagnosticTag, Range, } from "vscode-languageserver"; -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; import { PositionUtil } from "../common/positionUtil"; import { DiagnosticSource } from "../common/providers/diagnostics/diagnosticSource"; import { getSpaces } from "../common/util/refactorEditUtils"; @@ -24,9 +24,9 @@ function format(text: string, ...args: (string | number)[]): string { } export function errorWithEndNode( - node: SyntaxNode, + node: Node, diagnostic: IDiagnosticMessage, - endNode?: SyntaxNode, + endNode?: Node, ...args: (string | number)[] ): Diagnostic { return { @@ -45,7 +45,7 @@ export function errorWithEndNode( } export function error( - node: SyntaxNode, + node: Node, diagnostic: IDiagnosticMessage, ...args: (string | number)[] ): Diagnostic { diff --git a/src/compiler/forest.ts b/src/compiler/forest.ts index f24608db..54831e3c 100644 --- a/src/compiler/forest.ts +++ b/src/compiler/forest.ts @@ -1,4 +1,4 @@ -import { SyntaxNode, Tree } from "web-tree-sitter"; +import { Node, Tree } from "web-tree-sitter"; import { Imports } from "./imports"; import { TreeUtils } from "../common/util/treeUtils"; import { SyntaxNodeMap } from "./utils/syntaxNodeMap"; @@ -24,7 +24,7 @@ export interface ISourceFile { // Resolved during binding exposing?: IExposing; - symbolLinks?: SyntaxNodeMap; + symbolLinks?: SyntaxNodeMap; nonShadowableNames?: Set; // Top level function names // This is resolved while getting semantic diagnostics and defines whether we have loaded all import files diff --git a/src/compiler/imports.ts b/src/compiler/imports.ts index 904f0da5..7ffe5d1f 100644 --- a/src/compiler/imports.ts +++ b/src/compiler/imports.ts @@ -1,4 +1,4 @@ -import Parser, { SyntaxNode } from "web-tree-sitter"; +import Parser, { Node } from "web-tree-sitter"; import { ISourceFile } from "./forest"; import { TreeUtils } from "../common/util/treeUtils"; import { container } from "tsyringe"; @@ -22,7 +22,7 @@ type FromModule = { export interface IImport extends ISymbol { fromModule: FromModule; - importNode?: SyntaxNode; + importNode?: Node; } function importModuleEqual(a: IImport, b: IImport): boolean { @@ -87,7 +87,7 @@ export class Imports { return this.diagnostics; } - private static cachedVirtualImports: SyntaxNode[]; + private static cachedVirtualImports: Node[]; public static getImports( sourceFile: ISourceFile, @@ -389,7 +389,7 @@ export class Imports { return result; } - public static getVirtualImports(): SyntaxNode[] { + public static getVirtualImports(): Node[] { if (this.cachedVirtualImports) { return this.cachedVirtualImports; } @@ -416,9 +416,7 @@ export class Imports { return (this.cachedVirtualImports = importTree.rootNode.children); } - private static findImportAsClause( - importNode: SyntaxNode, - ): string | undefined { + private static findImportAsClause(importNode: Node): string | undefined { const asClause = TreeUtils.findFirstNamedChildOfType( "as_clause", importNode, diff --git a/src/compiler/patternMatches.ts b/src/compiler/patternMatches.ts index 5c8bda6c..8ef5cda9 100644 --- a/src/compiler/patternMatches.ts +++ b/src/compiler/patternMatches.ts @@ -1,4 +1,4 @@ -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; import { TreeUtils } from "../common/util/treeUtils"; import { Utils } from "../common/util/utils"; import { Diagnostic, Diagnostics, error } from "./diagnostics"; @@ -49,7 +49,7 @@ type CanCtor = { arity: number; }; -function nodeToCanCtor(node: SyntaxNode): CanCtor { +function nodeToCanCtor(node: Node): CanCtor { return { name: node.firstNamedChild!.text, arity: node.namedChildren @@ -84,8 +84,8 @@ export class PatternMatches { ) {} public static check( - region: SyntaxNode, - patterns: SyntaxNode[], + region: Node, + patterns: Node[], program: IProgram, ): Diagnostic[] { return new PatternMatches( @@ -94,14 +94,14 @@ export class PatternMatches { ).checkPatterns(region, patterns); } - public static missing(patterns: SyntaxNode[], program: IProgram): string[] { + public static missing(patterns: Node[], program: IProgram): string[] { return new PatternMatches( program, program.getSourceFile(patterns[0].tree.uri)!, ).getMissing(patterns); } - private getMissing(patterns: SyntaxNode[]): string[] { + private getMissing(patterns: Node[]): string[] { const result = this.toNonRedundantRows(patterns[0], patterns); if (!Array.isArray(result)) { @@ -113,10 +113,7 @@ export class PatternMatches { } } - private checkPatterns( - region: SyntaxNode, - patterns: SyntaxNode[], - ): Diagnostic[] { + private checkPatterns(region: Node, patterns: Node[]): Diagnostic[] { const result = this.toNonRedundantRows(region, patterns); if (!Array.isArray(result)) { @@ -193,16 +190,16 @@ export class PatternMatches { } private toNonRedundantRows( - region: SyntaxNode, - patterns: SyntaxNode[], + region: Node, + patterns: Node[], ): Pattern[][] | Diagnostic { return this.toSimplifiedUsefulRows(region, [], patterns); } private toSimplifiedUsefulRows( - overalRegion: SyntaxNode, + overalRegion: Node, checkedRows: Pattern[][], - uncheckedPatterns: SyntaxNode[], + uncheckedPatterns: Node[], ): Pattern[][] | Diagnostic { if (uncheckedPatterns.length === 0) { return checkedRows; @@ -370,11 +367,11 @@ export class PatternMatches { return ctors; } - private cons(head: SyntaxNode, tail: Pattern): Pattern { + private cons(head: Node, tail: Pattern): Pattern { return Ctor(list, consName, [this.simplify(head), tail]); } - private simplify(pattern: SyntaxNode): Pattern { + private simplify(pattern: Node): Pattern { const patternAs = pattern.childForFieldName("patternAs"); if (patternAs) { return this.simplify(pattern.childForFieldName("child") ?? patternAs); @@ -391,6 +388,7 @@ export class PatternMatches { case "tuple_pattern": { const patterns = pattern.children + .filter((val) => val !== null) .filter((n) => n.type === "pattern") .map((n) => n.childForFieldName("child")!); @@ -420,7 +418,8 @@ export class PatternMatches { "type_declaration", definition.symbol.node, ) - ?.namedChildren.filter((n) => n.type === "union_variant") + ?.namedChildren.filter((val) => val !== null) + .filter((n) => n.type === "union_variant") .map(nodeToCanCtor) ?? [] : []; @@ -437,16 +436,20 @@ export class PatternMatches { return foldr( this.cons.bind(this), nil, - pattern.namedChildren.filter((n) => n.type === "pattern"), + pattern.namedChildren + .filter((val) => val !== null) + .filter((n) => n.type === "pattern"), ); case "cons_pattern": { - const patterns = pattern.namedChildren.filter( - (n) => - n.type.includes("pattern") || - n.type.includes("constant") || - n.type === "unit_expr", - ); + const patterns = pattern.namedChildren + .filter((val) => val !== null) + .filter( + (n) => + n.type.includes("pattern") || + n.type.includes("constant") || + n.type === "unit_expr", + ); return this.cons(patterns[0], this.simplify(patterns[1])); } diff --git a/src/compiler/references.ts b/src/compiler/references.ts index 882aa9e4..80fbf67b 100644 --- a/src/compiler/references.ts +++ b/src/compiler/references.ts @@ -1,6 +1,6 @@ import { IProgram } from "./program"; import { ISourceFile } from "./forest"; -import { SyntaxNode, Tree } from "web-tree-sitter"; +import { Node, Tree } from "web-tree-sitter"; import { TreeUtils } from "../common/util/treeUtils"; import { Utils } from "../common/util/utils"; import { Imports } from "./imports"; @@ -10,8 +10,8 @@ export class References { public static find( definitionNode: ISymbol | undefined, program: IProgram, - ): { node: SyntaxNode; uri: string }[] { - const references: { node: SyntaxNode; uri: string }[] = []; + ): { node: Node; uri: string }[] { + const references: { node: Node; uri: string }[] = []; const checker = program.getTypeChecker(); @@ -684,7 +684,7 @@ export class References { true, ); - const typeVariableNodes: SyntaxNode[] = []; + const typeVariableNodes: Node[] = []; if (topLevelAnnotation) { const topLevelValueDeclaration = @@ -747,10 +747,7 @@ export class References { return references; } - public static findOperator( - node: SyntaxNode, - program: IProgram, - ): SyntaxNode | undefined { + public static findOperator(node: Node, program: IProgram): Node | undefined { const functionNameNode = TreeUtils.getFunctionNameNodeFromDefinition(node); if (functionNameNode) { @@ -767,9 +764,9 @@ export class References { } private static findFunctionCalls( - node: SyntaxNode, + node: Node, functionName: string, - ): SyntaxNode[] | undefined { + ): Node[] | undefined { const functions = [ ...this.findAllFunctionCallsAndParameters(node).concat(), ...node.descendantsOfType("record_base_identifier"), @@ -780,9 +777,7 @@ export class References { return result.length === 0 ? undefined : result; } - private static findAllFunctionCallsAndParameters( - node: SyntaxNode, - ): SyntaxNode[] { + private static findAllFunctionCallsAndParameters(node: Node): Node[] { let functions = TreeUtils.descendantsOfType(node, "value_expr"); if (functions.length > 0) { functions = functions @@ -794,10 +789,10 @@ export class References { } private static findParameterUsage( - node: SyntaxNode, + node: Node, functionName: string, - ): SyntaxNode[] | undefined { - const parameters: SyntaxNode[] = [ + ): Node[] | undefined { + const parameters: Node[] = [ ...this.findAllFunctionCallsAndParameters(node), ...this.findAllRecordBaseIdentifiers(node), ]; @@ -805,11 +800,11 @@ export class References { return result.length === 0 ? undefined : result; } - private static findAllRecordBaseIdentifiers(node: SyntaxNode): SyntaxNode[] { + private static findAllRecordBaseIdentifiers(node: Node): Node[] { return TreeUtils.descendantsOfType(node, "record_base_identifier"); } - private static findFieldUsages(tree: Tree, fieldName: string): SyntaxNode[] { + private static findFieldUsages(tree: Tree, fieldName: string): Node[] { return tree.rootNode .descendantsOfType([ "field", @@ -853,8 +848,8 @@ export class References { definition: ISymbol, sourceFile: ISourceFile, program: IProgram, - ): { node: SyntaxNode; uri: string }[] { - const references: { node: SyntaxNode; uri: string }[] = []; + ): { node: Node; uri: string }[] { + const references: { node: Node; uri: string }[] = []; const fieldUsages = References.findFieldUsages(sourceFile.tree, fieldName); diff --git a/src/compiler/typeCache.ts b/src/compiler/typeCache.ts index 76d1902f..89e9dbb9 100644 --- a/src/compiler/typeCache.ts +++ b/src/compiler/typeCache.ts @@ -1,4 +1,4 @@ -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; import { MultiMap } from "../common/util/multiMap"; import { TreeUtils } from "../common/util/treeUtils"; import { SyntaxNodeMap } from "./utils/syntaxNodeMap"; @@ -15,44 +15,26 @@ type CacheKey = | "PROJECT_UNION_VARIANT"; export class TypeCache { - private packageTypeAnnotation: SyntaxNodeMap; - private packageTypeAndTypeAlias: SyntaxNodeMap; - private packageValueDeclaration: SyntaxNodeMap; - private packageUnionVariant: SyntaxNodeMap; - private projectTypeAnnotation: SyntaxNodeMap; - private projectTypeAndTypeAlias: SyntaxNodeMap; - private projectValueDeclaration: SyntaxNodeMap; - private projectUnionVariant: SyntaxNodeMap; - private declarationAnnotations: MultiMap; - private typeUnionVariants: MultiMap; + private packageTypeAnnotation: SyntaxNodeMap; + private packageTypeAndTypeAlias: SyntaxNodeMap; + private packageValueDeclaration: SyntaxNodeMap; + private packageUnionVariant: SyntaxNodeMap; + private projectTypeAnnotation: SyntaxNodeMap; + private projectTypeAndTypeAlias: SyntaxNodeMap; + private projectValueDeclaration: SyntaxNodeMap; + private projectUnionVariant: SyntaxNodeMap; + private declarationAnnotations: MultiMap; + private typeUnionVariants: MultiMap; constructor() { - this.packageTypeAnnotation = new SyntaxNodeMap< - SyntaxNode, - InferenceResult - >(); - this.packageTypeAndTypeAlias = new SyntaxNodeMap< - SyntaxNode, - InferenceResult - >(); - this.packageValueDeclaration = new SyntaxNodeMap< - SyntaxNode, - InferenceResult - >(); - this.packageUnionVariant = new SyntaxNodeMap(); - this.projectTypeAnnotation = new SyntaxNodeMap< - SyntaxNode, - InferenceResult - >(); - this.projectTypeAndTypeAlias = new SyntaxNodeMap< - SyntaxNode, - InferenceResult - >(); - this.projectValueDeclaration = new SyntaxNodeMap< - SyntaxNode, - InferenceResult - >(); - this.projectUnionVariant = new SyntaxNodeMap(); + this.packageTypeAnnotation = new SyntaxNodeMap(); + this.packageTypeAndTypeAlias = new SyntaxNodeMap(); + this.packageValueDeclaration = new SyntaxNodeMap(); + this.packageUnionVariant = new SyntaxNodeMap(); + this.projectTypeAnnotation = new SyntaxNodeMap(); + this.projectTypeAndTypeAlias = new SyntaxNodeMap(); + this.projectValueDeclaration = new SyntaxNodeMap(); + this.projectUnionVariant = new SyntaxNodeMap(); this.declarationAnnotations = new MultiMap(); this.typeUnionVariants = new MultiMap(); @@ -60,7 +42,7 @@ export class TypeCache { public getOrSet( key: CacheKey, - node: SyntaxNode, + node: Node, setter: () => InferenceResult, ): InferenceResult { switch (key) { @@ -90,18 +72,18 @@ export class TypeCache { this.projectUnionVariant.clear(); } - public invalidateValueDeclaration(node: SyntaxNode): void { + public invalidateValueDeclaration(node: Node): void { this.projectValueDeclaration.delete(node); this.declarationAnnotations .getAll(node.id) ?.forEach((annotation) => this.projectTypeAnnotation.delete(annotation)); } - public invalidateTypeAnnotation(node: SyntaxNode): void { + public invalidateTypeAnnotation(node: Node): void { this.projectTypeAnnotation.delete(node); } - public invalidateTypeOrTypeAlias(node: SyntaxNode): void { + public invalidateTypeOrTypeAlias(node: Node): void { this.projectTypeAndTypeAlias.delete(node); this.typeUnionVariants .getAll(node.id) @@ -114,7 +96,7 @@ export class TypeCache { * We associate type annotations with its top level declaration * so we can clear its cache when we invalidate that declaration */ - public trackTypeAnnotation(annotation: SyntaxNode): void { + public trackTypeAnnotation(annotation: Node): void { const declaration = annotation.parent?.type === "file" ? TreeUtils.getValueDeclaration(annotation) @@ -129,7 +111,7 @@ export class TypeCache { } } - public trackUnionVariant(unionVariant: SyntaxNode): void { + public trackUnionVariant(unionVariant: Node): void { const typeDeclaration = TreeUtils.findParentOfType( "type_declaration", unionVariant, diff --git a/src/compiler/typeChecker.ts b/src/compiler/typeChecker.ts index fdfbfa9d..f50a0576 100644 --- a/src/compiler/typeChecker.ts +++ b/src/compiler/typeChecker.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; import { TreeUtils } from "../common/util/treeUtils"; import { Expression, @@ -58,13 +58,10 @@ class DiagnosticsCollection extends Map { } export interface TypeChecker { - findType: (node: SyntaxNode) => Type; - findDefinition: ( - node: SyntaxNode, - sourceFile: ISourceFile, - ) => DefinitionResult; + findType: (node: Node) => Type; + findDefinition: (node: Node, sourceFile: ISourceFile) => DefinitionResult; findDefinitionShallow: ( - node: SyntaxNode, + node: Node, sourceFile: ISourceFile, ) => DefinitionResult; getAllImports: (sourceFile: ISourceFile) => Imports; @@ -94,8 +91,8 @@ export interface TypeChecker { findImportModuleNameNodes: ( moduleNameOrAlias: string, sourceFile: ISourceFile, - ) => SyntaxNode[]; - getSymbolsInScope(node: SyntaxNode, sourceFile: ISourceFile): ISymbol[]; + ) => Node[]; + getSymbolsInScope(node: Node, sourceFile: ISourceFile): ISymbol[]; } export function createTypeChecker(program: IProgram): TypeChecker { @@ -131,7 +128,7 @@ export function createTypeChecker(program: IProgram): TypeChecker { return typeChecker; - function findType(node: SyntaxNode): Type { + function findType(node: Node): Type { try { const declaration = mapSyntaxNodeToExpression( TreeUtils.findParentOfType("value_declaration", node, true), @@ -140,7 +137,7 @@ export function createTypeChecker(program: IProgram): TypeChecker { const uri = node.tree.uri; const findTypeOrParentType = ( - expr: SyntaxNode | undefined, + expr: Node | undefined, inferenceResult: InferenceResult, ): Type | undefined => { const found = expr @@ -419,7 +416,7 @@ export function createTypeChecker(program: IProgram): TypeChecker { } function findDefinition( - nodeAtPosition: SyntaxNode, + nodeAtPosition: Node, sourceFile: ISourceFile, ): DefinitionResult { const definition = findDefinitionShallow(nodeAtPosition, sourceFile); @@ -442,7 +439,7 @@ export function createTypeChecker(program: IProgram): TypeChecker { } function findDefinitionShallow( - nodeAtPosition: SyntaxNode, + nodeAtPosition: Node, sourceFile: ISourceFile, ): DefinitionResult { const nodeText = nodeAtPosition.text; @@ -848,12 +845,12 @@ export function createTypeChecker(program: IProgram): TypeChecker { parentType, ]; - const callback = (annotation: SyntaxNode | undefined): SyntaxNode[] => + const callback = (annotation: Node | undefined): Node[] => annotation ? TreeUtils.descendantsOfType(annotation, "type_variable") : []; - const allTypeVariables: SyntaxNode[] = allAnnotations.flatMap(callback); + const allTypeVariables: Node[] = allAnnotations.flatMap(callback); const firstMatching = allTypeVariables.find((t) => t.text === nodeText); @@ -932,7 +929,7 @@ export function createTypeChecker(program: IProgram): TypeChecker { function findImportModuleNameNodes( moduleNameOrAlias: string, sourceFile: ISourceFile, - ): SyntaxNode[] { + ): Node[] { // This will find an import based on module name only, not alias const moduleImport = getAllImports(sourceFile) .getModule(moduleNameOrAlias) @@ -957,13 +954,10 @@ export function createTypeChecker(program: IProgram): TypeChecker { return moduleOrAliasImports; } - function getSymbolsInScope( - node: SyntaxNode, - sourceFile: ISourceFile, - ): ISymbol[] { + function getSymbolsInScope(node: Node, sourceFile: ISourceFile): ISymbol[] { const symbols: ISymbol[] = []; - let targetScope: SyntaxNode | null = node; + let targetScope: Node | null = node; while (targetScope != null) { sourceFile.symbolLinks ?.get(targetScope) @@ -974,7 +968,7 @@ export function createTypeChecker(program: IProgram): TypeChecker { return symbols; } - function checkNode(node: SyntaxNode): void { + function checkNode(node: Node): void { if (checkedNodes.has(node.id)) { return; } @@ -1008,7 +1002,7 @@ export function createTypeChecker(program: IProgram): TypeChecker { checkedNodes.add(node.id); } - function checkValueDeclaration(valueDeclaration: SyntaxNode): void { + function checkValueDeclaration(valueDeclaration: Node): void { const declaration = mapSyntaxNodeToExpression( valueDeclaration, ) as EValueDeclaration; @@ -1045,7 +1039,7 @@ export function createTypeChecker(program: IProgram): TypeChecker { } } - function checkImportClause(importClause: SyntaxNode): void { + function checkImportClause(importClause: Node): void { const moduleNameNode = importClause.childForFieldName("moduleName"); if (moduleNameNode) { @@ -1062,14 +1056,14 @@ export function createTypeChecker(program: IProgram): TypeChecker { } } - function checkTypeAliasDeclaration(typeAliasDeclaration: SyntaxNode): void { + function checkTypeAliasDeclaration(typeAliasDeclaration: Node): void { TypeExpression.typeAliasDeclarationInference( mapSyntaxNodeToExpression(typeAliasDeclaration) as ETypeAliasDeclaration, program, ).diagnostics.forEach((diagnostic) => diagnostics.add(diagnostic)); } - function checkTypeDeclaration(typeDeclaration: SyntaxNode): void { + function checkTypeDeclaration(typeDeclaration: Node): void { TypeExpression.typeDeclarationInference( mapSyntaxNodeToExpression(typeDeclaration) as ETypeDeclaration, program, @@ -1079,21 +1073,21 @@ export function createTypeChecker(program: IProgram): TypeChecker { typeDeclaration.children.forEach(checkNode); } - function checkUnionVariant(unionVariant: SyntaxNode): void { + function checkUnionVariant(unionVariant: Node): void { TypeExpression.unionVariantInference( mapSyntaxNodeToExpression(unionVariant) as EUnionVariant, program, ).diagnostics.forEach((diagnostic) => diagnostics.add(diagnostic)); } - function checkPortAnnotation(portAnnotation: SyntaxNode): void { + function checkPortAnnotation(portAnnotation: Node): void { TypeExpression.portAnnotationInference( mapSyntaxNodeToExpression(portAnnotation) as EPortAnnotation, program, ).diagnostics.forEach((diagnostic) => diagnostics.add(diagnostic)); } - function getSourceFileOfNode(node: SyntaxNode): ISourceFile { + function getSourceFileOfNode(node: Node): ISourceFile { const sourceFile = program.getSourceFile(node.tree.uri); if (!sourceFile) { diff --git a/src/compiler/typeInference.ts b/src/compiler/typeInference.ts index e8d2cdbc..528b413c 100644 --- a/src/compiler/typeInference.ts +++ b/src/compiler/typeInference.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; import { TreeUtils } from "../common/util/treeUtils"; import { References } from "./references"; import { @@ -377,10 +377,10 @@ export function nthVarName(n: number): string { function typeMismatchError( checker: TypeChecker, - node: SyntaxNode, + node: Node, found: Type, expected: Type, - endNode?: SyntaxNode, + endNode?: Node, patternBinding = false, recordDiff?: RecordDiff, ): Diagnostic { @@ -424,8 +424,8 @@ function typeMismatchError( } function parameterCountError( - node: SyntaxNode, - endNode: SyntaxNode, + node: Node, + endNode: Node, actual: number, expected: number, isType = false, @@ -443,8 +443,8 @@ function parameterCountError( } function argumentCountError( - node: SyntaxNode, - endNode: SyntaxNode, + node: Node, + endNode: Node, actual: number, expected: number, isType = false, @@ -495,10 +495,7 @@ export class InferenceScope { new SyntaxNodeMap(); private diagnostics: Diagnostic[] = []; - private bindings: SyntaxNodeMap = new SyntaxNodeMap< - SyntaxNode, - Type - >(); + private bindings: SyntaxNodeMap = new SyntaxNodeMap(); private replacements: DisjointSet; private annotationVars: TVar[] = []; diff --git a/src/compiler/utils/expressionTree.ts b/src/compiler/utils/expressionTree.ts index 881ca160..b9c7595e 100644 --- a/src/compiler/utils/expressionTree.ts +++ b/src/compiler/utils/expressionTree.ts @@ -1,4 +1,4 @@ -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; import { OperatorAssociativity } from "../operatorPrecedence"; import { TreeUtils } from "../../common/util/treeUtils"; import { Utils } from "../../common/util/utils"; @@ -63,205 +63,205 @@ export type Expression = | EValueDeclaration | EValueExpr; -export interface EValueDeclaration extends SyntaxNode { +export interface EValueDeclaration extends Node { nodeType: "ValueDeclaration"; params: string[]; - body?: SyntaxNode; - typeAnnotation?: SyntaxNode; - pattern?: SyntaxNode; + body?: Node; + typeAnnotation?: Node; + pattern?: Node; } -export interface EFunctionCallExpr extends SyntaxNode { +export interface EFunctionCallExpr extends Node { nodeType: "FunctionCallExpr"; target: Expression; args: Expression[]; } -export interface EIfElseExpr extends SyntaxNode { +export interface EIfElseExpr extends Node { nodeType: "IfElseExpr"; exprList: Expression[]; } -export interface ELetInExpr extends SyntaxNode { +export interface ELetInExpr extends Node { nodeType: "LetInExpr"; valueDeclarations: EValueDeclaration[]; body: Expression; } -export interface ECaseOfExpr extends SyntaxNode { +export interface ECaseOfExpr extends Node { nodeType: "CaseOfExpr"; expr: Expression; branches: ECaseOfBranch[]; } -export interface ECaseOfBranch extends SyntaxNode { +export interface ECaseOfBranch extends Node { nodeType: "CaseOfBranch"; pattern: EPattern; expr: Expression; } -export interface EAnonymousFunctionExpr extends SyntaxNode { +export interface EAnonymousFunctionExpr extends Node { nodeType: "AnonymousFunctionExpr"; params: EPattern[]; expr: Expression; } -export interface EUnionVariant extends SyntaxNode { +export interface EUnionVariant extends Node { nodeType: "UnionVariant"; name: string; params: Expression[]; } -export interface EUnionPattern extends SyntaxNode { +export interface EUnionPattern extends Node { nodeType: "UnionPattern"; - constructor: SyntaxNode; + constructor: Node; namedParams: Expression[]; argPatterns: Expression[]; } -export interface EValueExpr extends SyntaxNode { +export interface EValueExpr extends Node { nodeType: "ValueExpr"; name: string; } -export interface EBinOpExpr extends SyntaxNode { +export interface EBinOpExpr extends Node { nodeType: "BinOpExpr"; parts: Expression[]; } -export interface EOperator extends SyntaxNode { +export interface EOperator extends Node { nodeType: "Operator"; } -export interface EOperatorAsFunctionExpr extends SyntaxNode { +export interface EOperatorAsFunctionExpr extends Node { nodeType: "OperatorAsFunctionExpr"; operator: EOperator; } -export interface ENumberConstant extends SyntaxNode { +export interface ENumberConstant extends Node { nodeType: "NumberConstant"; isFloat: boolean; } -export interface EStringConstant extends SyntaxNode { +export interface EStringConstant extends Node { nodeType: "StringConstant"; } -export interface ETypeExpression extends SyntaxNode { +export interface ETypeExpression extends Node { nodeType: "TypeExpression"; segments: Expression[]; } -export interface ETypeRef extends SyntaxNode { +export interface ETypeRef extends Node { nodeType: "TypeRef"; } -export interface ETypeDeclaration extends SyntaxNode { +export interface ETypeDeclaration extends Node { nodeType: "TypeDeclaration"; name: string; typeNames: Expression[]; } -export interface ETypeVariable extends SyntaxNode { +export interface ETypeVariable extends Node { nodeType: "TypeVariable"; } -export interface ETypeAnnotation extends SyntaxNode { +export interface ETypeAnnotation extends Node { nodeType: "TypeAnnotation"; name: string; typeExpression?: ETypeExpression; } -export interface EInfixDeclaration extends SyntaxNode { +export interface EInfixDeclaration extends Node { nodeType: "InfixDeclaration"; precedence: number; associativity: OperatorAssociativity; } -export interface EFunctionDeclarationLeft extends SyntaxNode { +export interface EFunctionDeclarationLeft extends Node { nodeType: "FunctionDeclarationLeft"; params: Pattern[]; } type Pattern = EPattern | ELowerPattern; -export interface EPattern extends SyntaxNode { +export interface EPattern extends Node { nodeType: "Pattern"; patternAs?: ELowerPattern; } -export interface ELowerPattern extends SyntaxNode { +export interface ELowerPattern extends Node { nodeType: "LowerPattern"; } -export interface ELowerTypeName extends SyntaxNode { +export interface ELowerTypeName extends Node { nodeType: "LowerTypeName"; } -export interface EUnitExpr extends SyntaxNode { +export interface EUnitExpr extends Node { nodeType: "UnitExpr"; } -export interface ETupleExpr extends SyntaxNode { +export interface ETupleExpr extends Node { nodeType: "TupleExpr"; exprList: Expression[]; } -export interface EAnythingPattern extends SyntaxNode { +export interface EAnythingPattern extends Node { nodeType: "AnythingPattern"; } -export interface ETuplePattern extends SyntaxNode { +export interface ETuplePattern extends Node { nodeType: "TuplePattern"; patterns: EPattern[]; } -export interface ETupleType extends SyntaxNode { +export interface ETupleType extends Node { nodeType: "TupleType"; typeExpressions: ETypeExpression[]; unitExpr?: EUnitExpr; } -export interface EListExpr extends SyntaxNode { +export interface EListExpr extends Node { nodeType: "ListExpr"; exprList: Expression[]; } -export interface EListPattern extends SyntaxNode { +export interface EListPattern extends Node { nodeType: "ListPattern"; parts: Expression[]; } -export interface EConsPattern extends SyntaxNode { +export interface EConsPattern extends Node { nodeType: "ConsPattern"; parts: Expression[]; } -export interface EFieldType extends SyntaxNode { +export interface EFieldType extends Node { nodeType: "FieldType"; name: string; typeExpression: ETypeExpression; } -export interface ERecordType extends SyntaxNode { +export interface ERecordType extends Node { nodeType: "RecordType"; baseType: Expression; fieldTypes: EFieldType[]; } -export interface ETypeAliasDeclaration extends SyntaxNode { +export interface ETypeAliasDeclaration extends Node { nodeType: "TypeAliasDeclaration"; - name: SyntaxNode; + name: Node; typeVariables: Expression[]; typeExpression: ETypeExpression; } -export interface EField extends SyntaxNode { +export interface EField extends Node { nodeType: "Field"; name: Expression; expression: Expression; } -export interface EFieldAccessExpr extends SyntaxNode { +export interface EFieldAccessExpr extends Node { nodeType: "FieldAccessExpr"; target: Expression; } -export interface EFieldAccessorFunctionExpr extends SyntaxNode { +export interface EFieldAccessorFunctionExpr extends Node { nodeType: "FieldAccessorFunctionExpr"; } -export interface ERecordPattern extends SyntaxNode { +export interface ERecordPattern extends Node { nodeType: "RecordPattern"; patternList: ELowerPattern[]; } -export interface ERecordExpr extends SyntaxNode { +export interface ERecordExpr extends Node { nodeType: "RecordExpr"; - baseRecord: SyntaxNode; + baseRecord: Node; fields: EField[]; } -export interface EPortAnnotation extends SyntaxNode { +export interface EPortAnnotation extends Node { nodeType: "PortAnnotation"; name: string; typeExpression: ETypeExpression; } -export interface ECharConstantExpr extends SyntaxNode { +export interface ECharConstantExpr extends Node { nodeType: "CharConstantExpr"; } -export interface EGlslCodeExpr extends SyntaxNode { +export interface EGlslCodeExpr extends Node { nodeType: "GlslCodeExpr"; - content: SyntaxNode; + content: Node; } -export interface ENegateExpr extends SyntaxNode { +export interface ENegateExpr extends Node { nodeType: "NegateExpr"; expression: Expression; } -export interface ENullaryConstructorArgumentPattern extends SyntaxNode { +export interface ENullaryConstructorArgumentPattern extends Node { nodeType: "NullaryConstructorArgumentPattern"; } export function mapSyntaxNodeToExpression( - node: SyntaxNode | null | undefined, + node: Node | null | undefined, ): Expression | undefined { if (!node) return; @@ -571,7 +571,7 @@ export function mapSyntaxNodeToExpression( case "union_pattern": { const unionPattern = node as EUnionPattern; unionPattern.nodeType = "UnionPattern"; - unionPattern.constructor = node.firstNamedChild as SyntaxNode; + unionPattern.constructor = node.firstNamedChild as Node; unionPattern.namedParams = node .descendantsOfType("lower_pattern") .map(mapSyntaxNodeToExpression) @@ -673,9 +673,7 @@ export function mapSyntaxNodeToExpression( case "record_expr": { const recordExpr = node as ERecordExpr; recordExpr.nodeType = "RecordExpr"; - recordExpr.baseRecord = node.childForFieldName( - "baseRecord", - ) as SyntaxNode; + recordExpr.baseRecord = node.childForFieldName("baseRecord") as Node; recordExpr.fields = (TreeUtils.findAllNamedChildrenOfType("field", node) ?.map(mapSyntaxNodeToExpression) @@ -739,7 +737,7 @@ export function mapTypeAliasDeclaration( ): void { typeAliasDeclaration.name = typeAliasDeclaration.childForFieldName( "name", - ) as SyntaxNode; + ) as Node; typeAliasDeclaration.typeVariables = TreeUtils.findAllNamedChildrenOfType( "lower_type_name", @@ -769,7 +767,7 @@ export function mapTypeAnnotation(typeAnnotation: ETypeAnnotation): void { } export function findDefinition( - e: SyntaxNode | undefined | null, + e: Node | undefined | null, program: IProgram, ): { expr?: Expression; diagnostics: Diagnostic[] } { if (!e) { diff --git a/src/compiler/utils/recordFieldReferenceTable.ts b/src/compiler/utils/recordFieldReferenceTable.ts index e5637b44..9f637362 100644 --- a/src/compiler/utils/recordFieldReferenceTable.ts +++ b/src/compiler/utils/recordFieldReferenceTable.ts @@ -1,4 +1,4 @@ -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; import { EFieldType } from "./expressionTree"; import { SyntaxNodeSet } from "./syntaxNodeSet"; @@ -29,7 +29,7 @@ export class RecordFieldReferenceTable { return new RecordFieldReferenceTable(fieldRefs); } - public get(field: string): SyntaxNode[] { + public get(field: string): Node[] { return this.refsByField.get(field)?.toArray() ?? []; } diff --git a/src/compiler/utils/syntaxNodeMap.ts b/src/compiler/utils/syntaxNodeMap.ts index 1a2cfdce..15c47a2f 100644 --- a/src/compiler/utils/syntaxNodeMap.ts +++ b/src/compiler/utils/syntaxNodeMap.ts @@ -1,6 +1,6 @@ -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; -export class SyntaxNodeMap { +export class SyntaxNodeMap { private map: Map = new Map(); public set(key: K, value: V): void { diff --git a/src/compiler/utils/syntaxNodeSet.ts b/src/compiler/utils/syntaxNodeSet.ts index e83f65c9..3fd746d2 100644 --- a/src/compiler/utils/syntaxNodeSet.ts +++ b/src/compiler/utils/syntaxNodeSet.ts @@ -1,6 +1,6 @@ -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; -export class SyntaxNodeSet { +export class SyntaxNodeSet { private map = new Map(); constructor(...items: K[]) { diff --git a/src/typings/web-tree-sitter/index.d.ts b/src/typings/web-tree-sitter/index.d.ts deleted file mode 100644 index 2c808c38..00000000 --- a/src/typings/web-tree-sitter/index.d.ts +++ /dev/null @@ -1,54 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import "web-tree-sitter"; - -declare module "web-tree-sitter" { - export interface SyntaxNode { - id: number; - } - - export interface Tree { - uri: string; - } - - interface QueryResult { - pattern: number; - captures: { name: string; node: SyntaxNode }[]; - } - - interface PredicateResult { - operator: string; - operands: { name: string; type: string }[]; - } - - interface Query { - captureNames: string[]; - - delete(): void; - matches( - node: SyntaxNode, - startPosition?: Point, - endPosition?: Point, - ): QueryResult[]; - captures( - node: SyntaxNode, - startPosition?: Point, - endPosition?: Point, - ): QueryResult[]; - - predicatesForPattern(patternIndex: number): PredicateResult[]; - } - - interface Language { - query(source: string): Query; - } - - class Parser { - static init(): Promise; - delete(): void; - parse(input: string | Input, previousTree?: Tree, options?: Options): Tree; - getLanguage(): Language; - setLanguage(language: Language): void; - getLogger(): Logger; - setLogger(logFunc: Logger): void; - } -} diff --git a/test/diagnosticTests/elmDiagnostics.test.ts b/test/diagnosticTests/elmDiagnostics.test.ts index f162be34..6ae6aa8f 100644 --- a/test/diagnosticTests/elmDiagnostics.test.ts +++ b/test/diagnosticTests/elmDiagnostics.test.ts @@ -1,5 +1,5 @@ import { Utils as UriUtils } from "vscode-uri"; -import { SyntaxNode } from "web-tree-sitter"; +import { Node } from "web-tree-sitter"; import { convertFromCompilerDiagnostic } from "../../src/common/providers"; import { diagnosticsEquals } from "../../src/common/providers/diagnostics/fileDiagnostics"; import { TreeUtils } from "../../src/common/util/treeUtils"; @@ -78,7 +78,7 @@ describe("test elm diagnostics", () => { } }); - let nodeAtPosition: SyntaxNode = undefined!; + let nodeAtPosition: Node = undefined!; if ("range" in result) { const rootNode = program.getSourceFile(testUri)!.tree.rootNode; @@ -1545,11 +1545,11 @@ a = --@ Test.elm module Test exposing (..) -type alias A appendable = +type alias A appendable = { a : appendable } a : A Int -a = +a = { a = 0 } `; await testTypeInference(basicsSources + source3, []); @@ -1560,10 +1560,10 @@ a = --@ Test.elm module Test exposing (..) -type alias A appendable = +type alias A appendable = { a : appendable } -a = +a = A 0 --^ `; @@ -1575,7 +1575,7 @@ a = --@ Test.elm module Test exposing (..) -type B appendable = +type B appendable = With appendable | Without b : B Int @@ -1590,7 +1590,7 @@ b = With 0 --@ Test.elm module Test exposing (..) -type B appendable = +type B appendable = With appendable | Without b : B Int @@ -1718,7 +1718,7 @@ oneOrMore parser = ) parser - + --@ Test.elm module Test exposing (..) @@ -1727,7 +1727,7 @@ import Parser.Advanced as Parser exposing ((|.), (|=)) test : Parser.Parser Never () () test = Parser.succeed (\\_ -> ()) - |= Parser.getOffset + |= Parser.getOffset `; await testTypeInference( diff --git a/tree-sitter-elm.wasm b/tree-sitter-elm.wasm index aa7cef58..9da02513 100755 Binary files a/tree-sitter-elm.wasm and b/tree-sitter-elm.wasm differ