From 5f010571e8a41155853a10bb9c50b16c3ed6ea1f Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Wed, 12 Feb 2025 23:28:27 +0300 Subject: [PATCH 01/12] fixed errors in the `no-unused-vars` rule --- eslint.config.mjs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 33de49d7..186e52a7 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -53,7 +53,14 @@ export default tseslint.config( "@typescript-eslint/prefer-optional-chain": "off", // override strictTypeChecked - "@typescript-eslint/no-unused-vars": "off", + "@typescript-eslint/no-unused-vars": [ + "error", + { + argsIgnorePattern: "^_", + caughtErrorsIgnorePattern: "^_", + varsIgnorePattern: "^_", + }, + ], "@typescript-eslint/no-base-to-string": "off", "@typescript-eslint/unbound-method": "off", "@typescript-eslint/no-misused-promises": "off", From b94356a5413dd3f7a533ba1ecef7963ab3f43517 Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Wed, 12 Feb 2025 23:28:48 +0300 Subject: [PATCH 02/12] fixed errors in the `no-base-to-string` rule --- client/src/client-log.ts | 1 + eslint.config.mjs | 1 - server/src/utils/logger.ts | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/client/src/client-log.ts b/client/src/client-log.ts index ff570a14..ad8aef48 100644 --- a/client/src/client-log.ts +++ b/client/src/client-log.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-base-to-string */ import * as vscode from "vscode" let consoleLogChannel: vscode.OutputChannel | null = null diff --git a/eslint.config.mjs b/eslint.config.mjs index 186e52a7..cdcc4120 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -61,7 +61,6 @@ export default tseslint.config( varsIgnorePattern: "^_", }, ], - "@typescript-eslint/no-base-to-string": "off", "@typescript-eslint/unbound-method": "off", "@typescript-eslint/no-misused-promises": "off", "@typescript-eslint/no-extraneous-class": "off", diff --git a/server/src/utils/logger.ts b/server/src/utils/logger.ts index 4faed4c8..ab559651 100644 --- a/server/src/utils/logger.ts +++ b/server/src/utils/logger.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-base-to-string */ import type {Connection} from "vscode-languageserver" import * as fs from "node:fs" import * as path from "node:path" From f8073db067bfb90d35eedcae2a52ebbc36008d88 Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Wed, 12 Feb 2025 23:29:47 +0300 Subject: [PATCH 03/12] fixed errors in the `unbound-method` rule --- eslint.config.mjs | 1 - server/src/server.ts | 3 --- 2 files changed, 4 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index cdcc4120..26b7ef0c 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -61,7 +61,6 @@ export default tseslint.config( varsIgnorePattern: "^_", }, ], - "@typescript-eslint/unbound-method": "off", "@typescript-eslint/no-misused-promises": "off", "@typescript-eslint/no-extraneous-class": "off", diff --git a/server/src/server.ts b/server/src/server.ts index 2358e3be..30b02094 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -1535,9 +1535,6 @@ connection.onInitialize(async (initParams: lsp.InitializeParams): Promise Date: Wed, 12 Feb 2025 23:34:21 +0300 Subject: [PATCH 04/12] fixed errors in the `no-misused-promises` rule --- eslint.config.mjs | 1 - server/src/server.ts | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 26b7ef0c..e87d7dd3 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -61,7 +61,6 @@ export default tseslint.config( varsIgnorePattern: "^_", }, ], - "@typescript-eslint/no-misused-promises": "off", "@typescript-eslint/no-extraneous-class": "off", "@typescript-eslint/prefer-readonly": "error", diff --git a/server/src/server.ts b/server/src/server.ts index 30b02094..be9c5cd8 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -217,6 +217,7 @@ async function initialize() { initialized = true } +// eslint-disable-next-line @typescript-eslint/no-misused-promises connection.onInitialized(async () => { await initialize() }) From 672d9beddf7c0eb47ffc99ad98fd0d083445ba33 Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Wed, 12 Feb 2025 23:35:24 +0300 Subject: [PATCH 05/12] fixed errors in the `prefer-readonly` rule --- eslint.config.mjs | 1 - 1 file changed, 1 deletion(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index e87d7dd3..07a7206a 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -63,7 +63,6 @@ export default tseslint.config( ], "@typescript-eslint/no-extraneous-class": "off", - "@typescript-eslint/prefer-readonly": "error", "@typescript-eslint/switch-exhaustiveness-check": "error", "@unused-imports/no-unused-imports": "error", From 84c69cfc90dbe2e7a5443ce8e57d84397a5b5c1b Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Wed, 12 Feb 2025 23:35:38 +0300 Subject: [PATCH 06/12] fixed errors in the `switch-exhaustiveness-check` rule --- eslint.config.mjs | 2 -- 1 file changed, 2 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 07a7206a..4bfcac3b 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -63,8 +63,6 @@ export default tseslint.config( ], "@typescript-eslint/no-extraneous-class": "off", - "@typescript-eslint/switch-exhaustiveness-check": "error", - "@unused-imports/no-unused-imports": "error", "no-duplicate-imports": "error", From 9f699528646e2efb445f3524fff50320175d041a Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Wed, 12 Feb 2025 23:36:49 +0300 Subject: [PATCH 07/12] move --- eslint.config.mjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 4bfcac3b..4d9644b2 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -63,9 +63,7 @@ export default tseslint.config( ], "@typescript-eslint/no-extraneous-class": "off", - "@unused-imports/no-unused-imports": "error", - "no-duplicate-imports": "error", - + // override all "@typescript-eslint/no-magic-numbers": "off", "@typescript-eslint/no-unsafe-type-assertion": "off", "@typescript-eslint/prefer-readonly-parameter-types": "off", @@ -76,7 +74,6 @@ export default tseslint.config( "@typescript-eslint/prefer-destructuring": "off", "@typescript-eslint/strict-boolean-expressions": "off", "@typescript-eslint/no-use-before-define": "off", - "@typescript-eslint/class-methods-use-this": "off", "@typescript-eslint/no-shadow": "off", "@typescript-eslint/consistent-type-imports": "off", @@ -85,6 +82,9 @@ export default tseslint.config( "@typescript-eslint/no-invalid-this": "off", "@typescript-eslint/init-declarations": "off", + "@unused-imports/no-unused-imports": "error", + "no-duplicate-imports": "error", + // override unicorn "unicorn/no-null": "off", "unicorn/prevent-abbreviations": "off", From 754a7a2e74169fa2e0fd13321409899d0a49b02d Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Thu, 13 Feb 2025 00:01:45 +0300 Subject: [PATCH 08/12] fixed errors in the `explicit-function-return-type` rule --- client/src/extension.ts | 4 ++-- eslint.config.mjs | 7 ++++++- server/src/TypeInferer.ts | 6 +++--- .../providers/PostfixCompletionProvider.ts | 2 +- server/src/documentation/documentation.ts | 2 +- .../documentation/receivers_documentation.ts | 2 +- server/src/e2e/runTest.ts | 2 +- server/src/e2e/suite/completion.test.ts | 2 +- server/src/e2e/suite/doc.test.ts | 2 +- server/src/e2e/suite/inspection.test.ts | 2 +- server/src/e2e/suite/intentions.test.ts | 2 +- server/src/e2e/suite/references.test.ts | 2 +- server/src/e2e/suite/rename.test.ts | 4 ++-- server/src/e2e/suite/resolve.test.ts | 2 +- server/src/e2e/suite/types.test.ts | 2 +- server/src/fift/semantic_tokens/collect.ts | 2 +- .../MissedFieldInContractInspection.ts | 2 +- .../StructInitializationInspection.ts | 2 +- .../UnusedContractMembersInspection.ts | 2 +- .../inspections/UnusedParameterInspection.ts | 2 +- server/src/intentions/AddExplicitType.ts | 3 ++- server/src/intentions/AddFieldInitialization.ts | 5 +++-- server/src/intentions/AddImport.ts | 3 ++- server/src/intentions/FillAllStructInit.ts | 8 ++++---- server/src/intentions/WrapSelected.ts | 2 +- server/src/lens/collect.ts | 2 +- server/src/psi/Reference.ts | 2 +- server/src/psi/Referent.ts | 4 ++-- server/src/psi/visitor.ts | 2 +- server/src/semantic_tokens/collect.ts | 2 +- server/src/server.ts | 17 ++++++++++------- server/src/utils/logger.ts | 2 +- 32 files changed, 58 insertions(+), 47 deletions(-) diff --git a/client/src/extension.ts b/client/src/extension.ts index cdea5ec0..c500531c 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -89,7 +89,7 @@ async function showReferencesImpl( client: LanguageClient | undefined, uri: string, position: Position, -) { +): Promise { if (!client) return await vscode.commands.executeCommand( "editor.action.showReferences", @@ -99,7 +99,7 @@ async function showReferencesImpl( ) } -function registerCommands(disposables: vscode.Disposable[]) { +function registerCommands(disposables: vscode.Disposable[]): void { disposables.push( vscode.commands.registerCommand( "tact.showParent", diff --git a/eslint.config.mjs b/eslint.config.mjs index 4d9644b2..faf8fe7f 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -68,7 +68,12 @@ export default tseslint.config( "@typescript-eslint/no-unsafe-type-assertion": "off", "@typescript-eslint/prefer-readonly-parameter-types": "off", "@typescript-eslint/member-ordering": "off", - "@typescript-eslint/explicit-function-return-type": "off", + "@typescript-eslint/explicit-function-return-type": [ + "error", + { + allowExpressions: true, + }, + ], "@typescript-eslint/parameter-properties": "off", "@typescript-eslint/method-signature-style": "off", "@typescript-eslint/prefer-destructuring": "off", diff --git a/server/src/TypeInferer.ts b/server/src/TypeInferer.ts index 8954722d..a290520b 100644 --- a/server/src/TypeInferer.ts +++ b/server/src/TypeInferer.ts @@ -346,13 +346,13 @@ export class TypeInferer { return null } - private primitiveType(name: string) { + private primitiveType(name: string): PrimitiveTy | null { const node = index.elementByName(IndexKey.Primitives, name) if (!node) return null return new PrimitiveTy(name, node, null) } - private inferTypeMaybeOption(typeNode: SyntaxNode, resolved: Node) { + private inferTypeMaybeOption(typeNode: SyntaxNode, resolved: Node): Ty | null { const inferred = this.inferType(new Expression(typeNode, resolved.file)) if (inferred && !(inferred instanceof OptionTy) && typeNode.nextSibling?.text === "?") { return new OptionTy(inferred) @@ -360,7 +360,7 @@ export class TypeInferer { return inferred } - private inferTypeMaybeTlB(typeNode: SyntaxNode, resolved: Node) { + private inferTypeMaybeTlB(typeNode: SyntaxNode, resolved: Node): Ty | null { const inferredType = this.inferTypeMaybeOption(typeNode, resolved) if (inferredType instanceof PrimitiveTy) { const tlb = resolved.node.childForFieldName("tlb") diff --git a/server/src/completion/providers/PostfixCompletionProvider.ts b/server/src/completion/providers/PostfixCompletionProvider.ts index 604b0c7d..87c71b73 100644 --- a/server/src/completion/providers/PostfixCompletionProvider.ts +++ b/server/src/completion/providers/PostfixCompletionProvider.ts @@ -28,7 +28,7 @@ export class PostfixCompletionProvider implements CompletionProvider { description: string, snippet: string, result: CompletionResult, - ) { + ): void { const expr = ctx.element.node.parent if (expr?.type !== "field_access_expression") return const object = expr.childForFieldName("object") diff --git a/server/src/documentation/documentation.ts b/server/src/documentation/documentation.ts index 2b0f1d08..f7f1e3a4 100644 --- a/server/src/documentation/documentation.ts +++ b/server/src/documentation/documentation.ts @@ -284,6 +284,6 @@ function extractCommentsDoc(node: NamedNode): string { return result.trimEnd() } -function defaultResult(signature: string, documentation: string = "") { +function defaultResult(signature: string, documentation: string = ""): string { return DOC_TMPL.replace("{signature}", signature).replace("{documentation}", documentation) } diff --git a/server/src/documentation/receivers_documentation.ts b/server/src/documentation/receivers_documentation.ts index acd5beeb..c06a89f7 100644 --- a/server/src/documentation/receivers_documentation.ts +++ b/server/src/documentation/receivers_documentation.ts @@ -79,7 +79,7 @@ export function generateReceiverDoc(func: MessageFunction): string | null { return defaultResult(name, "", link) } -function defaultResult(name: string, doc: string, link: string) { +function defaultResult(name: string, doc: string, link: string): string { return ( `${CODE_FENCE}tact\n${name} {}\n${CODE_FENCE}` + "\n" + diff --git a/server/src/e2e/runTest.ts b/server/src/e2e/runTest.ts index 65d9bdf1..e4c0b937 100644 --- a/server/src/e2e/runTest.ts +++ b/server/src/e2e/runTest.ts @@ -1,7 +1,7 @@ import * as path from "node:path" import {runTests} from "@vscode/test-electron" -async function main() { +async function main(): Promise { try { const extensionDevelopmentPath = path.resolve(__dirname, "../../../") const extensionTestsPath = path.resolve(__dirname, "./out/suite/index.js") diff --git a/server/src/e2e/suite/completion.test.ts b/server/src/e2e/suite/completion.test.ts index 5b509898..fbc599db 100644 --- a/server/src/e2e/suite/completion.test.ts +++ b/server/src/e2e/suite/completion.test.ts @@ -29,7 +29,7 @@ suite("Completion Test Suite", () => { ) } - protected runTest(testFile: string, testCase: TestCase) { + protected runTest(testFile: string, testCase: TestCase): void { test(`Completion: ${testCase.name}`, async () => { const completions = await this.getCompletions(testCase.input, ".") diff --git a/server/src/e2e/suite/doc.test.ts b/server/src/e2e/suite/doc.test.ts index fd9d2c43..30e17d03 100644 --- a/server/src/e2e/suite/doc.test.ts +++ b/server/src/e2e/suite/doc.test.ts @@ -41,7 +41,7 @@ suite("Documentation Test Suite", () => { return (hover.contents as lsp.MarkupContent).value.trimEnd() } - protected runTest(testFile: string, testCase: TestCase) { + protected runTest(testFile: string, testCase: TestCase): void { test(`Documentation: ${testCase.name}`, async () => { const hovers = await this.getHovers(testCase.input) const actual = hovers diff --git a/server/src/e2e/suite/inspection.test.ts b/server/src/e2e/suite/inspection.test.ts index 0467b2e8..11ef74ed 100644 --- a/server/src/e2e/suite/inspection.test.ts +++ b/server/src/e2e/suite/inspection.test.ts @@ -28,7 +28,7 @@ suite("Inspection Test Suite", () => { .join("\n") } - protected runTest(testFile: string, testCase: TestCase) { + protected runTest(testFile: string, testCase: TestCase): void { test(`Inspection: ${testCase.name}`, async () => { await this.replaceDocumentText(testCase.input) diff --git a/server/src/e2e/suite/intentions.test.ts b/server/src/e2e/suite/intentions.test.ts index 92649b43..b5979a4b 100644 --- a/server/src/e2e/suite/intentions.test.ts +++ b/server/src/e2e/suite/intentions.test.ts @@ -39,7 +39,7 @@ suite("Intentions Test Suite", () => { ) } - protected runTest(testFile: string, testCase: TestCase) { + protected runTest(testFile: string, testCase: TestCase): void { test(`Intention: ${testCase.name}`, async () => { const actions = await this.getCodeActions(testCase.input) diff --git a/server/src/e2e/suite/references.test.ts b/server/src/e2e/suite/references.test.ts index 240e5bde..65fd804e 100644 --- a/server/src/e2e/suite/references.test.ts +++ b/server/src/e2e/suite/references.test.ts @@ -65,7 +65,7 @@ suite("References Test Suite", () => { .join("\n\n") } - protected runTest(testFile: string, testCase: TestCase) { + protected runTest(testFile: string, testCase: TestCase): void { test(`References: ${testCase.name}`, async () => { const caretIndexes = this.findCaretPositions(testCase.input) const positions = caretIndexes.map(index => diff --git a/server/src/e2e/suite/rename.test.ts b/server/src/e2e/suite/rename.test.ts index b30ebfc9..00d2516e 100644 --- a/server/src/e2e/suite/rename.test.ts +++ b/server/src/e2e/suite/rename.test.ts @@ -32,7 +32,7 @@ suite("Rename Test Suite", () => { return positions } - private async renameTo(position: vscode.Position, newName: string) { + private async renameTo(position: vscode.Position, newName: string): Promise { const result = await vscode.commands.executeCommand( "vscode.executeDocumentRenameProvider", this.document.uri, @@ -45,7 +45,7 @@ suite("Rename Test Suite", () => { } } - protected runTest(testFile: string, testCase: TestCase) { + protected runTest(testFile: string, testCase: TestCase): void { test(`Rename: ${testCase.name}`, async () => { const positions = this.findRenamePositions(testCase.input) diff --git a/server/src/e2e/suite/resolve.test.ts b/server/src/e2e/suite/resolve.test.ts index c6a1be07..04811bd0 100644 --- a/server/src/e2e/suite/resolve.test.ts +++ b/server/src/e2e/suite/resolve.test.ts @@ -63,7 +63,7 @@ suite("Resolve Test Suite", () => { .join("\n") } - protected runTest(testFile: string, testCase: TestCase) { + protected runTest(testFile: string, testCase: TestCase): void { test(`Resolve: ${testCase.name}`, async () => { const caretIndexes = this.findCaretPositions(testCase.input) const positions = caretIndexes.map(index => diff --git a/server/src/e2e/suite/types.test.ts b/server/src/e2e/suite/types.test.ts index 06653990..371344a8 100644 --- a/server/src/e2e/suite/types.test.ts +++ b/server/src/e2e/suite/types.test.ts @@ -65,7 +65,7 @@ suite("Type Inference Test Suite", () => { return response.type ?? undefined } - protected runTest(testFile: string, testCase: TestCase) { + protected runTest(testFile: string, testCase: TestCase): void { test(`Types: ${testCase.name}`, async () => { const positions = this.findTypePositions(testCase.input) diff --git a/server/src/fift/semantic_tokens/collect.ts b/server/src/fift/semantic_tokens/collect.ts index 5169d319..797cbd23 100644 --- a/server/src/fift/semantic_tokens/collect.ts +++ b/server/src/fift/semantic_tokens/collect.ts @@ -19,7 +19,7 @@ export function collectFift( const builder = new SemanticTokensBuilder() - function pushToken(n: SyntaxNode, tokenType: lsp.SemanticTokenTypes) { + function pushToken(n: SyntaxNode, tokenType: lsp.SemanticTokenTypes): void { builder.push( n.startPosition.row, n.startPosition.column, diff --git a/server/src/inspections/MissedFieldInContractInspection.ts b/server/src/inspections/MissedFieldInContractInspection.ts index b3bba02f..195b8222 100644 --- a/server/src/inspections/MissedFieldInContractInspection.ts +++ b/server/src/inspections/MissedFieldInContractInspection.ts @@ -14,7 +14,7 @@ export class MissedFieldInContractInspection extends UnusedInspection implements }) } - private inspectContract(contract: Contract, diagnostics: lsp.Diagnostic[]) { + private inspectContract(contract: Contract, diagnostics: lsp.Diagnostic[]): void { const inheritedTraits = contract.inheritTraits() if (inheritedTraits.length === 0) return // nothing to check diff --git a/server/src/inspections/StructInitializationInspection.ts b/server/src/inspections/StructInitializationInspection.ts index d2cf4de1..df71fbc0 100644 --- a/server/src/inspections/StructInitializationInspection.ts +++ b/server/src/inspections/StructInitializationInspection.ts @@ -22,7 +22,7 @@ export class StructInitializationInspection implements Inspection { return diagnostics } - private checkStructLiteral(node: SyntaxNode, diagnostics: lsp.Diagnostic[]) { + private checkStructLiteral(node: SyntaxNode, diagnostics: lsp.Diagnostic[]): void { const structName = node.childForFieldName("name") if (!structName) return const args = node.childForFieldName("arguments") diff --git a/server/src/inspections/UnusedContractMembersInspection.ts b/server/src/inspections/UnusedContractMembersInspection.ts index baeed96b..333b60c2 100644 --- a/server/src/inspections/UnusedContractMembersInspection.ts +++ b/server/src/inspections/UnusedContractMembersInspection.ts @@ -14,7 +14,7 @@ export class UnusedContractMembersInspection extends UnusedInspection implements }) } - private inspectContract(contract: Contract, diagnostics: lsp.Diagnostic[]) { + private inspectContract(contract: Contract, diagnostics: lsp.Diagnostic[]): void { contract.ownFields().forEach(field => { const nameIdent = field.nameIdentifier() if (!nameIdent) return diff --git a/server/src/inspections/UnusedParameterInspection.ts b/server/src/inspections/UnusedParameterInspection.ts index c687a76d..51f8c5f1 100644 --- a/server/src/inspections/UnusedParameterInspection.ts +++ b/server/src/inspections/UnusedParameterInspection.ts @@ -25,7 +25,7 @@ export class UnusedParameterInspection extends UnusedInspection implements Inspe }) } - private inspectFunction(fun: Fun, diagnostics: lsp.Diagnostic[]) { + private inspectFunction(fun: Fun, diagnostics: lsp.Diagnostic[]): void { if (!fun.hasBody()) return const parameters = fun.parameters() diff --git a/server/src/intentions/AddExplicitType.ts b/server/src/intentions/AddExplicitType.ts index ed21bb68..702fb53d 100644 --- a/server/src/intentions/AddExplicitType.ts +++ b/server/src/intentions/AddExplicitType.ts @@ -5,6 +5,7 @@ import {asLspPosition, asParserPoint} from "@server/utils/position" import type {Position} from "vscode-languageclient" import {VarDeclaration} from "@server/psi/Node" import {FileDiff} from "@server/utils/FileDiff" +import {Node} from "web-tree-sitter" export class AddExplicitType implements Intention { public readonly id: string = "tact.add-explicit-type" @@ -42,7 +43,7 @@ export class AddExplicitType implements Intention { } } -function nodeAtPosition(pos: Position, file: File) { +function nodeAtPosition(pos: Position, file: File): Node | null { const cursorPosition = asParserPoint(pos) return file.rootNode.descendantForPosition(cursorPosition) } diff --git a/server/src/intentions/AddFieldInitialization.ts b/server/src/intentions/AddFieldInitialization.ts index fd825c7a..10ba0283 100644 --- a/server/src/intentions/AddFieldInitialization.ts +++ b/server/src/intentions/AddFieldInitialization.ts @@ -7,6 +7,7 @@ import {FileDiff} from "@server/utils/FileDiff" import {Field, StorageMembersOwner} from "@server/psi/Decls" import type {Ty} from "@server/types/BaseTy" import {RecursiveVisitor} from "@server/psi/RecursiveVisitor" +import {Node} from "web-tree-sitter" export class AddFieldInitialization implements Intention { public readonly id: string = "tact.add-field-to-init" @@ -125,7 +126,7 @@ export class AddFieldInitialization implements Intention { resolved: Field, type: Ty, owner: StorageMembersOwner, - ) { + ): WorkspaceEdit { const initFunctionTemplate = ` init($name: $type) { self.$name = $name; @@ -162,7 +163,7 @@ export class AddFieldInitialization implements Intention { } } -function nodeAtPosition(pos: Position, file: File) { +function nodeAtPosition(pos: Position, file: File): Node | null { const cursorPosition = asParserPoint(pos) return file.rootNode.descendantForPosition(cursorPosition) } diff --git a/server/src/intentions/AddImport.ts b/server/src/intentions/AddImport.ts index ec9872b2..584db6bc 100644 --- a/server/src/intentions/AddImport.ts +++ b/server/src/intentions/AddImport.ts @@ -7,6 +7,7 @@ import {NamedNode} from "@server/psi/Node" import {FileDiff} from "@server/utils/FileDiff" import {Reference} from "@server/psi/Reference" import {Contract, Primitive} from "@server/psi/Decls" +import {Node} from "web-tree-sitter" export class AddImport implements Intention { public readonly id: string = "tact.add-import" @@ -49,7 +50,7 @@ export class AddImport implements Intention { } } -function nodeAtPosition(pos: Position, file: File) { +function nodeAtPosition(pos: Position, file: File): Node | null { const cursorPosition = asParserPoint(pos) return file.rootNode.descendantForPosition(cursorPosition) } diff --git a/server/src/intentions/FillAllStructInit.ts b/server/src/intentions/FillAllStructInit.ts index 3eac73b6..863c14d5 100644 --- a/server/src/intentions/FillAllStructInit.ts +++ b/server/src/intentions/FillAllStructInit.ts @@ -5,7 +5,7 @@ import {asLspPosition, asParserPoint} from "@server/utils/position" import type {Position} from "vscode-languageclient" import {FileDiff} from "@server/utils/FileDiff" import {parentOfType} from "@server/psi/utils" -import type {Node as SyntaxNode} from "web-tree-sitter" +import type {Node, Node as SyntaxNode} from "web-tree-sitter" import {NamedNode} from "@server/psi/Node" import {TypeInferer} from "@server/TypeInferer" import { @@ -44,7 +44,7 @@ export class FillStructInitBase implements Intention { return args.length === 0 } - private static findBraces(instance: SyntaxNode) { + private static findBraces(instance: SyntaxNode): {openBrace: Node; closeBrace: Node} | null { const args = instance.childForFieldName("arguments") if (!args) return null @@ -54,7 +54,7 @@ export class FillStructInitBase implements Intention { return {openBrace, closeBrace} } - private static findIndent(ctx: IntentionContext, instance: SyntaxNode) { + private static findIndent(ctx: IntentionContext, instance: SyntaxNode): number { const lines = ctx.file.content.split(/\r?\n/) const line = lines[instance.startPosition.row] const lineTrim = line.trimStart() @@ -201,7 +201,7 @@ export class FillRequiredStructInit extends FillStructInitBase { } } -function nodeAtPosition(pos: Position, file: File) { +function nodeAtPosition(pos: Position, file: File): Node | null { const cursorPosition = asParserPoint(pos) return file.rootNode.descendantForPosition(cursorPosition) } diff --git a/server/src/intentions/WrapSelected.ts b/server/src/intentions/WrapSelected.ts index a77a5d45..7e8ef78a 100644 --- a/server/src/intentions/WrapSelected.ts +++ b/server/src/intentions/WrapSelected.ts @@ -74,7 +74,7 @@ export class WrapSelected implements Intention { return this.findStatements(ctx).length > 0 } - private static findIndent(ctx: IntentionContext, node: SyntaxNode) { + private static findIndent(ctx: IntentionContext, node: SyntaxNode): number { const lines = ctx.file.content.split(/\r?\n/) const line = lines[node.startPosition.row] const lineTrim = line.trimStart() diff --git a/server/src/lens/collect.ts b/server/src/lens/collect.ts index d70334c4..b85ccacc 100644 --- a/server/src/lens/collect.ts +++ b/server/src/lens/collect.ts @@ -194,7 +194,7 @@ export function collect( return result } -function usagesLens(n: SyntaxNode, file: File, result: lsp.CodeLens[]) { +function usagesLens(n: SyntaxNode, file: File, result: lsp.CodeLens[]): void { // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if (file.fromStdlib || !file.fromStdlib) { // disabled for now diff --git a/server/src/psi/Reference.ts b/server/src/psi/Reference.ts index ddd4a3a9..6d6c669b 100644 --- a/server/src/psi/Reference.ts +++ b/server/src/psi/Reference.ts @@ -203,7 +203,7 @@ export class Reference { qualifierType: Ty | StructTy | MessageTy | TraitTy | ContractTy, proc: ScopeProcessor, state: ResolveState, - ) { + ): boolean { const methodRef = qualifier.node.parent?.type === "method_call_expression" if (!this.processTypeMethods(qualifierType, proc, state)) return false diff --git a/server/src/psi/Referent.ts b/server/src/psi/Referent.ts index 68d6c909..012586df 100644 --- a/server/src/psi/Referent.ts +++ b/server/src/psi/Referent.ts @@ -109,7 +109,7 @@ export class Referent { sameFileOnly: boolean, includeSelf: boolean, result: Node[], - ) { + ): void { if (!this.resolved) return if (scope instanceof LocalSearchScope) { @@ -128,7 +128,7 @@ export class Referent { } } - private traverseTree(file: File, node: SyntaxNode, includeSelf: boolean, result: Node[]) { + private traverseTree(file: File, node: SyntaxNode, includeSelf: boolean, result: Node[]): void { const resolved = this.resolved if (!resolved) return diff --git a/server/src/psi/visitor.ts b/server/src/psi/visitor.ts index 9add7387..fc576900 100644 --- a/server/src/psi/visitor.ts +++ b/server/src/psi/visitor.ts @@ -33,7 +33,7 @@ class TreeWalker { return this.cursor.currentNode } - public skipChildren() { + public skipChildren(): void { this.alreadyVisitedChildren = true } } diff --git a/server/src/semantic_tokens/collect.ts b/server/src/semantic_tokens/collect.ts index ded3e4e6..33697dbd 100644 --- a/server/src/semantic_tokens/collect.ts +++ b/server/src/semantic_tokens/collect.ts @@ -10,7 +10,7 @@ import {isNamedFunNode} from "@server/psi/utils" export function collect(file: File): SemanticTokens { const builder = new lsp.SemanticTokensBuilder() - function pushToken(n: SyntaxNode, tokenType: lsp.SemanticTokenTypes) { + function pushToken(n: SyntaxNode, tokenType: lsp.SemanticTokenTypes): void { builder.push( n.startPosition.row, n.startPosition.column, diff --git a/server/src/server.ts b/server/src/server.ts index be9c5cd8..4ac9b04d 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -128,7 +128,7 @@ let clientInfo: {name?: string; version?: string} = {name: "", version: ""} */ let workspaceFolders: lsp.WorkspaceFolder[] | null = null -const showErrorMessage = (msg: string) => { +const showErrorMessage = (msg: string): void => { void connection.sendNotification(lsp.ShowMessageNotification.type, { type: lsp.MessageType.Error, message: msg, @@ -169,7 +169,7 @@ function findStdlib(settings: TactSettings, rootDir: string): string | null { return stdlibPath } -async function initialize() { +async function initialize(): Promise { if (!workspaceFolders || workspaceFolders.length === 0 || initialized) { // use fallback later, see `initializeFallback` return @@ -241,7 +241,7 @@ function findConfigFileDir(startPath: string, fileName: string): string | null { // For some reason some editors (like Neovim) doesn't pass workspace folders to initialization. // So we need to find root first and then call initialize. -async function initializeFallback(uri: string) { +async function initializeFallback(uri: string): Promise { // let's try to initialize with this way const projectDir = findConfigFileDir(path.dirname(uri.slice(7)), "tact.config.json") if (projectDir === null) { @@ -372,7 +372,7 @@ connection.onInitialize(async (initParams: lsp.InitializeParams): Promise { + const usageKind = (value: Node): lsp.DocumentHighlightKind => { const parent = value.node.parent if ( parent?.type === "assignment_statement" || @@ -1390,7 +1390,7 @@ connection.onInitialize(async (initParams: lsp.InitializeParams): Promise { to.push({ diff --git a/server/src/utils/logger.ts b/server/src/utils/logger.ts index ab559651..a8d093ea 100644 --- a/server/src/utils/logger.ts +++ b/server/src/utils/logger.ts @@ -81,7 +81,7 @@ export class Logger { } private static formatDate(date: Date): string { - const pad = (n: number) => n.toString().padStart(2, "0") + const pad = (n: number): string => n.toString().padStart(2, "0") const year = date.getFullYear().toString() const month = pad(date.getMonth() + 1) From 0026ad69f64d3f556dd13dedcb97db7599a3c530 Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Thu, 13 Feb 2025 00:08:58 +0300 Subject: [PATCH 09/12] move --- eslint.config.mjs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index faf8fe7f..eb26196d 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -42,7 +42,7 @@ export default tseslint.config( }, rules: { - // override stylisticTypeChecked + // override typescript-eslint "@typescript-eslint/no-empty-function": ["error", {allow: ["arrowFunctions"]}], "@typescript-eslint/no-inferrable-types": "off", "@typescript-eslint/typedef": [ @@ -50,9 +50,6 @@ export default tseslint.config( {parameter: true, memberVariableDeclaration: true}, ], "@typescript-eslint/consistent-generic-constructors": ["error", "type-annotation"], - "@typescript-eslint/prefer-optional-chain": "off", - - // override strictTypeChecked "@typescript-eslint/no-unused-vars": [ "error", { @@ -61,19 +58,18 @@ export default tseslint.config( varsIgnorePattern: "^_", }, ], - "@typescript-eslint/no-extraneous-class": "off", - - // override all - "@typescript-eslint/no-magic-numbers": "off", - "@typescript-eslint/no-unsafe-type-assertion": "off", - "@typescript-eslint/prefer-readonly-parameter-types": "off", - "@typescript-eslint/member-ordering": "off", "@typescript-eslint/explicit-function-return-type": [ "error", { allowExpressions: true, }, ], + "@typescript-eslint/prefer-optional-chain": "off", + "@typescript-eslint/no-extraneous-class": "off", + "@typescript-eslint/no-magic-numbers": "off", + "@typescript-eslint/no-unsafe-type-assertion": "off", + "@typescript-eslint/prefer-readonly-parameter-types": "off", + "@typescript-eslint/member-ordering": "off", "@typescript-eslint/parameter-properties": "off", "@typescript-eslint/method-signature-style": "off", "@typescript-eslint/prefer-destructuring": "off", From 84a54d6db8b8acc148c2e78d3da33ef507de2a7c Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Thu, 13 Feb 2025 00:27:29 +0300 Subject: [PATCH 10/12] review code --- server/src/fift/foldings/collect.ts | 2 +- server/src/intentions/AddExplicitType.ts | 4 ++-- server/src/intentions/AddFieldInitialization.ts | 4 ++-- server/src/intentions/AddImport.ts | 4 ++-- server/src/intentions/FillAllStructInit.ts | 9 ++++++--- server/src/lens/collect.ts | 2 +- server/src/psi/Decls.ts | 2 +- server/src/psi/Node.ts | 2 +- server/src/utils/position.ts | 10 +++++----- 9 files changed, 21 insertions(+), 18 deletions(-) diff --git a/server/src/fift/foldings/collect.ts b/server/src/fift/foldings/collect.ts index a16b6ab9..8c2a789e 100644 --- a/server/src/fift/foldings/collect.ts +++ b/server/src/fift/foldings/collect.ts @@ -1,7 +1,7 @@ import {FoldingRange, FoldingRangeKind} from "vscode-languageserver-types" import {RecursiveVisitor} from "@server/psi/visitor" import type {File} from "@server/psi/File" -import {Point} from "web-tree-sitter" +import type {Point} from "web-tree-sitter" import type * as lsp from "vscode-languageserver" export function collectFift(file: File): FoldingRange[] { diff --git a/server/src/intentions/AddExplicitType.ts b/server/src/intentions/AddExplicitType.ts index 702fb53d..9fe77cb4 100644 --- a/server/src/intentions/AddExplicitType.ts +++ b/server/src/intentions/AddExplicitType.ts @@ -5,7 +5,7 @@ import {asLspPosition, asParserPoint} from "@server/utils/position" import type {Position} from "vscode-languageclient" import {VarDeclaration} from "@server/psi/Node" import {FileDiff} from "@server/utils/FileDiff" -import {Node} from "web-tree-sitter" +import type {Node as SyntaxNode} from "web-tree-sitter" export class AddExplicitType implements Intention { public readonly id: string = "tact.add-explicit-type" @@ -43,7 +43,7 @@ export class AddExplicitType implements Intention { } } -function nodeAtPosition(pos: Position, file: File): Node | null { +function nodeAtPosition(pos: Position, file: File): SyntaxNode | null { const cursorPosition = asParserPoint(pos) return file.rootNode.descendantForPosition(cursorPosition) } diff --git a/server/src/intentions/AddFieldInitialization.ts b/server/src/intentions/AddFieldInitialization.ts index 10ba0283..8bc8322c 100644 --- a/server/src/intentions/AddFieldInitialization.ts +++ b/server/src/intentions/AddFieldInitialization.ts @@ -7,7 +7,7 @@ import {FileDiff} from "@server/utils/FileDiff" import {Field, StorageMembersOwner} from "@server/psi/Decls" import type {Ty} from "@server/types/BaseTy" import {RecursiveVisitor} from "@server/psi/RecursiveVisitor" -import {Node} from "web-tree-sitter" +import type {Node as SyntaxNode} from "web-tree-sitter" export class AddFieldInitialization implements Intention { public readonly id: string = "tact.add-field-to-init" @@ -163,7 +163,7 @@ export class AddFieldInitialization implements Intention { } } -function nodeAtPosition(pos: Position, file: File): Node | null { +function nodeAtPosition(pos: Position, file: File): SyntaxNode | null { const cursorPosition = asParserPoint(pos) return file.rootNode.descendantForPosition(cursorPosition) } diff --git a/server/src/intentions/AddImport.ts b/server/src/intentions/AddImport.ts index 584db6bc..90134584 100644 --- a/server/src/intentions/AddImport.ts +++ b/server/src/intentions/AddImport.ts @@ -7,7 +7,7 @@ import {NamedNode} from "@server/psi/Node" import {FileDiff} from "@server/utils/FileDiff" import {Reference} from "@server/psi/Reference" import {Contract, Primitive} from "@server/psi/Decls" -import {Node} from "web-tree-sitter" +import type {Node as SyntaxNode} from "web-tree-sitter" export class AddImport implements Intention { public readonly id: string = "tact.add-import" @@ -50,7 +50,7 @@ export class AddImport implements Intention { } } -function nodeAtPosition(pos: Position, file: File): Node | null { +function nodeAtPosition(pos: Position, file: File): SyntaxNode | null { const cursorPosition = asParserPoint(pos) return file.rootNode.descendantForPosition(cursorPosition) } diff --git a/server/src/intentions/FillAllStructInit.ts b/server/src/intentions/FillAllStructInit.ts index 863c14d5..acfca2f4 100644 --- a/server/src/intentions/FillAllStructInit.ts +++ b/server/src/intentions/FillAllStructInit.ts @@ -5,7 +5,7 @@ import {asLspPosition, asParserPoint} from "@server/utils/position" import type {Position} from "vscode-languageclient" import {FileDiff} from "@server/utils/FileDiff" import {parentOfType} from "@server/psi/utils" -import type {Node, Node as SyntaxNode} from "web-tree-sitter" +import type {Node as SyntaxNode} from "web-tree-sitter" import {NamedNode} from "@server/psi/Node" import {TypeInferer} from "@server/TypeInferer" import { @@ -44,7 +44,10 @@ export class FillStructInitBase implements Intention { return args.length === 0 } - private static findBraces(instance: SyntaxNode): {openBrace: Node; closeBrace: Node} | null { + private static findBraces(instance: SyntaxNode): { + openBrace: SyntaxNode + closeBrace: SyntaxNode + } | null { const args = instance.childForFieldName("arguments") if (!args) return null @@ -201,7 +204,7 @@ export class FillRequiredStructInit extends FillStructInitBase { } } -function nodeAtPosition(pos: Position, file: File): Node | null { +function nodeAtPosition(pos: Position, file: File): SyntaxNode | null { const cursorPosition = asParserPoint(pos) return file.rootNode.descendantForPosition(cursorPosition) } diff --git a/server/src/lens/collect.ts b/server/src/lens/collect.ts index b85ccacc..1e02efe1 100644 --- a/server/src/lens/collect.ts +++ b/server/src/lens/collect.ts @@ -1,7 +1,7 @@ import * as lsp from "vscode-languageserver" import {File} from "@server/psi/File" import {RecursiveVisitor} from "@server/psi/visitor" -import {Node as SyntaxNode} from "web-tree-sitter" +import type {Node as SyntaxNode} from "web-tree-sitter" import {isNamedFunNode, parentOfType} from "@server/psi/utils" import {Fun, StorageMembersOwner, Struct, Trait} from "@server/psi/Decls" import {NamedNode} from "@server/psi/Node" diff --git a/server/src/psi/Decls.ts b/server/src/psi/Decls.ts index 965f864e..87b6275f 100644 --- a/server/src/psi/Decls.ts +++ b/server/src/psi/Decls.ts @@ -2,7 +2,7 @@ import {Expression, NamedNode, Node} from "./Node" import {Reference} from "./Reference" import {index, IndexKey} from "@server/indexes" import {parentOfType} from "./utils" -import {Node as SyntaxNode} from "web-tree-sitter" +import type {Node as SyntaxNode} from "web-tree-sitter" import {findInstruction} from "@server/completion/data/types" import {crc16} from "@server/utils/crc16" import {Position} from "vscode-languageclient" diff --git a/server/src/psi/Node.ts b/server/src/psi/Node.ts index cb393fc0..6bb1c30b 100644 --- a/server/src/psi/Node.ts +++ b/server/src/psi/Node.ts @@ -1,4 +1,4 @@ -import {Node as SyntaxNode} from "web-tree-sitter" +import type {Node as SyntaxNode} from "web-tree-sitter" import {File} from "./File" import {Ty} from "@server/types/BaseTy" import {TypeInferer} from "@server/TypeInferer" diff --git a/server/src/utils/position.ts b/server/src/utils/position.ts index cddd2d75..cd35f742 100644 --- a/server/src/utils/position.ts +++ b/server/src/utils/position.ts @@ -1,7 +1,7 @@ import * as lsp from "vscode-languageserver/node" -import type * as Parser from "web-tree-sitter" +import type {Node as SyntaxNode, Point} from "web-tree-sitter" -export function asNullableLspRange(node: Parser.Node | null | undefined): lsp.Range { +export function asNullableLspRange(node: SyntaxNode | null | undefined): lsp.Range { if (!node) { return lsp.Range.create(0, 1, 0, 1) } @@ -14,7 +14,7 @@ export function asNullableLspRange(node: Parser.Node | null | undefined): lsp.Ra ) } -export function asLspRange(node: Parser.Node): lsp.Range { +export function asLspRange(node: SyntaxNode): lsp.Range { return lsp.Range.create( node.startPosition.row, node.startPosition.column, @@ -23,11 +23,11 @@ export function asLspRange(node: Parser.Node): lsp.Range { ) } -export function asLspPosition(pos: Parser.Point): lsp.Position { +export function asLspPosition(pos: Point): lsp.Position { return lsp.Position.create(pos.row, pos.column) } -export function asParserPoint(position: lsp.Position): Parser.Point { +export function asParserPoint(position: lsp.Position): Point { return { column: position.character, row: position.line, From d03a11b4cea199773250ebd38797979f9c1b56f7 Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Thu, 13 Feb 2025 00:29:34 +0300 Subject: [PATCH 11/12] review code --- server/src/server.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/src/server.ts b/server/src/server.ts index 4ac9b04d..68256d39 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -1535,6 +1535,9 @@ connection.onInitialize(async (initParams: lsp.InitializeParams): Promise Date: Thu, 13 Feb 2025 00:32:47 +0300 Subject: [PATCH 12/12] oops --- server/src/server.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/src/server.ts b/server/src/server.ts index 68256d39..ab8aeb52 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -1535,13 +1535,13 @@ connection.onInitialize(async (initParams: lsp.InitializeParams): Promise