sublimelsp / LSP-typescript

TypeScript, JavaScript support for Sublime LSP plugin
MIT License
131 stars 11 forks source link

Code action const to let has unexpected result (Mac) #238

Closed chris-plato closed 6 months ago

chris-plato commented 6 months ago

ℹī¸ Description

While vetting Sublime Text, I used the LSP-typescript code action convert 'const' to 'let' and it resulted in the following:

Pre-action:

export const warningHours = 1;

Post-action:

lett const warningHours = 1;

bad_action

There have been other formatting oddities using this feature, however this is my most recent example of this issue.

💁 Extra details

Logs ``` [14:18:00.662] --> LSP-typescript workspace/executeCommand (64): {'command': '_typescript.applyWorkspaceEdit', 'arguments': [{'documentChanges': [{'textDocument': {'version': 26, 'uri': 'file:///Users/chris/dev/plato/games/game-match3battle/lib/common/Config.ts'}, 'edits': [{'newText': 'let', 'range': {'start': {'character': 0, 'line': 27}, 'end': {'character': 5, 'line': 27}}}]}]}]} :: [14:18:00.664] <-- LSP-typescript workspace/applyEdit (1): {'edit': {'documentChanges': [{'textDocument': {'version': 26, 'uri': 'file:///Users/chris/dev/plato/games/game-match3battle/lib/common/Config.ts'}, 'edits': [{'newText': 'let', 'range': {'start': {'character': 0, 'line': 27}, 'end': {'character': 5, 'line': 27}}}]}]}} :: [14:18:00.672] >>> LSP-typescript (1) (duration: 7ms): {'applied': True} :: [14:18:00.682] <<< LSP-typescript (64) (duration: 20ms): None :: [14:18:00.982] -> LSP-eslint textDocument/didChange: {'contentChanges': [{'rangeLength': 5, 'range': {'start': {'line': 27, 'character': 0}, 'end': {'line': 27, 'character': 5}}, 'text': 'let'}], 'textDocument': {'version': 27, 'uri': 'file:///Users/chris/dev/plato/games/game-match3battle/lib/common/Config.ts'}} :: [14:18:00.983] -> LSP-typescript textDocument/didChange: {'contentChanges': [{'rangeLength': 5, 'range': {'start': {'line': 27, 'character': 0}, 'end': {'line': 27, 'character': 5}}, 'text': 'let'}], 'textDocument': {'version': 27, 'uri': 'file:///Users/chris/dev/plato/games/game-match3battle/lib/common/Config.ts'}} :: [14:18:00.984] --> LSP-typescript textDocument/codeLens (65): {'textDocument': {'uri': 'file:///Users/chris/dev/plato/games/game-match3battle/lib/common/Config.ts'}} :: [14:18:00.985] --> LSP-typescript textDocument/documentHighlight (66): {'textDocument': {'uri': 'file:///Users/chris/dev/plato/games/game-match3battle/lib/common/Config.ts'}, 'position': {'line': 28, 'character': 12}} :: [14:18:00.995] <<< LSP-typescript (65) (duration: 10ms): [] :: [14:18:01.007] <<< LSP-typescript (66) (duration: 22ms): [{'range': {'start': {'line': 27, 'character': 11}, 'end': {'line': 27, 'character': 23}}, 'kind': 2}, {'range': {'start': {'line': 28, 'character': 0}, 'end': {'line': 28, 'character': 12}}, 'kind': 2}] :: [14:18:01.343] <- LSP-typescript textDocument/publishDiagnostics: {'uri': 'file:///Users/chris/dev/plato/games/game-match3battle/lib/common/Config.ts', 'diagnostics': [{'range': {'start': {'line': 27, 'character': 5}, 'end': {'line': 27, 'character': 10}}, 'tags': [], 'severity': 1, 'source': 'typescript', 'code': 1005, 'message': "';' expected."}, {'range': {'start': {'line': 27, 'character': 0}, 'end': {'line': 27, 'character': 4}}, 'tags': [], 'severity': 1, 'source': 'typescript', 'code': 2304, 'message': "Cannot find name 'lett'."}, {'range': {'start': {'line': 28, 'character': 0}, 'end': {'line': 28, 'character': 12}}, 'tags': [], 'severity': 1, 'source': 'typescript', 'code': 2588, 'message': "Cannot assign to 'warningHours' because it is a constant."}]} :: [14:18:01.351] --> LSP-eslint textDocument/codeAction (24): {'context': {'triggerKind': 2, 'diagnostics': []}, 'range': {'start': {'line': 28, 'character': 0}, 'end': {'line': 28, 'character': 12}}, 'textDocument': {'uri': 'file:///Users/chris/dev/plato/games/game-match3battle/lib/common/Config.ts'}} :: [14:18:01.352] --> LSP-typescript textDocument/codeAction (67): {'context': {'triggerKind': 2, 'diagnostics': [{'range': {'start': {'line': 28, 'character': 0}, 'end': {'line': 28, 'character': 12}}, 'tags': [], 'severity': 1, 'source': 'typescript', 'code': 2588, 'message': "Cannot assign to 'warningHours' because it is a constant."}]}, 'range': {'start': {'line': 28, 'character': 0}, 'end': {'line': 28, 'character': 12}}, 'textDocument': {'uri': 'file:///Users/chris/dev/plato/games/game-match3battle/lib/common/Config.ts'}} :: [14:18:01.353] <<< LSP-eslint (24) (duration: 1ms): [] :: [14:18:01.356] <<< LSP-typescript (67) (duration: 4ms): [{'command': {'command': '_typescript.applyWorkspaceEdit', 'arguments': [{'documentChanges': [{'textDocument': {'version': 27, 'uri': 'file:///Users/chris/dev/plato/games/game-match3battle/lib/common/Config.ts'}, 'edits': [{'newText': 'let', 'range': {'start': {'line': 27, 'character': 5}, 'end': {'line': 27, 'character': 10}}}]}]}], 'title': "Convert 'const' to 'let'"}, 'kind': 'quickfix', 'title': "Convert 'const' to 'let'"}] ```
chris-plato commented 6 months ago

While trying to gather more info guided by rafal via discord, I have reproduced this same issue in a separate editor, as well as found that the issue is being caused by something strange in a specific project I'm working on 🤔

In any case, I will close this issue as it's clearly not a Sublime Text related problem.

Thank you for your time 🙇

predragnikolic commented 6 months ago

Could you please copy paste the following?

Just to get more insights on this

chris-plato commented 5 months ago

TS Version: 3.9.10

tsconfig.json ```json { "compilerOptions": { "baseUrl": ".", "paths": { "@plato/*": ["node_modules/@plato/*"] }, "target": "es5", "lib": ["es6"], "module": "commonjs", "strict": true, "noEmitHelpers": true, "importHelpers": true, "declaration": false, "types": [ "@plato/papi" ] } } ```
LSP-typescript.sublime-settings ```json { "initializationOptions": { "completionDisableFilterText": true, "disableAutomaticTypingAcquisition": false, "locale": "en", "maxTsServerMemory": 0, "npmLocation": "", "plugins": [], "preferences": { "allowIncompleteCompletions": true, "allowRenameOfImportPath": true, "allowTextChangesInNewFiles": true, "autoImportFileExcludePatterns": [], "disableSuggestions": false, "displayPartsForJSDoc": true, "excludeLibrarySymbolsInNavTo": true, "generateReturnInDocTemplate": true, "importModuleSpecifierEnding": "auto", "importModuleSpecifierPreference": "shortest", "includeAutomaticOptionalChainCompletions": true, "includeCompletionsForImportStatements": true, "includeCompletionsForModuleExports": true, "includeCompletionsWithClassMemberSnippets": true, "includeCompletionsWithInsertText": true, "includeCompletionsWithObjectLiteralMethodSnippets": true, "includeCompletionsWithSnippetText": true, "includePackageJsonAutoImports": "auto", "interactiveInlayHints": true, "jsxAttributeCompletionStyle": "auto", "lazyConfiguredProjectsFromExternalProject": false, "organizeImportsIgnoreCase": "auto", "organizeImportsCollation": "ordinal", "organizeImportsCollationLocale": "en", "organizeImportsNumericCollation": false, "organizeImportsAccentCollation": true, "organizeImportsCaseFirst": false, "providePrefixAndSuffixTextForRename": true, "provideRefactorNotApplicableReason": true, "quotePreference": "auto", "useLabelDetailsInCompletionEntries": true, }, "tsserver.logDirectory": "", "tsserver.logVerbosity": "off", "tsserver.path": "", "tsserver.fallbackPath": "", "tsserver.trace": "off", "tsserver.useSyntaxServer": "auto", }, "settings": { "statusText": "$version, $source", "diagnostics.ignoredCodes": [], // Implicit Project Configuration "implicitProjectConfiguration.checkJs": false, "implicitProjectConfiguration.experimentalDecorators": false, "implicitProjectConfiguration.module": "ESNext", "implicitProjectConfiguration.strictFunctionTypes": true, "implicitProjectConfiguration.strictNullChecks": true, "implicitProjectConfiguration.target": "ES2020", // Formatting options. "javascript.format.insertSpaceAfterCommaDelimiter": true, "javascript.format.insertSpaceAfterConstructor": false, "javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": true, "javascript.format.insertSpaceAfterKeywordsInControlFlowStatements": true, "javascript.format.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces": false, "javascript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false, "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true, "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false, "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false, "javascript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false, "javascript.format.insertSpaceAfterSemicolonInForStatements": true, "javascript.format.insertSpaceAfterTypeAssertion": false, "javascript.format.insertSpaceBeforeAndAfterBinaryOperators": true, "javascript.format.insertSpaceBeforeFunctionParenthesis": false, "javascript.format.insertSpaceBeforeTypeAnnotation": false, "javascript.format.placeOpenBraceOnNewLineForControlBlocks": false, "javascript.format.placeOpenBraceOnNewLineForFunctions": false, "javascript.format.semicolons": "ignore", // ignore | insert | remove "javascript.format.trimTrailingWhitespace": true, "typescript.format.insertSpaceAfterCommaDelimiter": true, "typescript.format.insertSpaceAfterConstructor": false, "typescript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": true, "typescript.format.insertSpaceAfterKeywordsInControlFlowStatements": true, "typescript.format.insertSpaceAfterOpeningAndBeforeClosingEmptyBraces": false, "typescript.format.insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false, "typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true, "typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false, "typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false, "typescript.format.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false, "typescript.format.insertSpaceAfterSemicolonInForStatements": true, "typescript.format.insertSpaceAfterTypeAssertion": false, "typescript.format.insertSpaceBeforeAndAfterBinaryOperators": true, "typescript.format.insertSpaceBeforeFunctionParenthesis": false, "typescript.format.insertSpaceBeforeTypeAnnotation": false, "typescript.format.placeOpenBraceOnNewLineForControlBlocks": false, "typescript.format.placeOpenBraceOnNewLineForFunctions": false, "typescript.format.semicolons": "ignore", // ignore | insert | remove "typescript.format.trimTrailingWhitespace": true, // Inlay hints options. "javascript.inlayHints.includeInlayEnumMemberValueHints": false, "javascript.inlayHints.includeInlayFunctionLikeReturnTypeHints": false, "javascript.inlayHints.includeInlayFunctionParameterTypeHints": false, "javascript.inlayHints.includeInlayParameterNameHints": "none", // none | literals | all "javascript.inlayHints.includeInlayParameterNameHintsWhenArgumentMatchesName": false, "javascript.inlayHints.includeInlayPropertyDeclarationTypeHints": false, "javascript.inlayHints.includeInlayVariableTypeHints": false, "javascript.inlayHints.includeInlayVariableTypeHintsWhenTypeMatchesName": false, "typescript.inlayHints.includeInlayEnumMemberValueHints": false, "typescript.inlayHints.includeInlayFunctionLikeReturnTypeHints": false, "typescript.inlayHints.includeInlayFunctionParameterTypeHints": false, "typescript.inlayHints.includeInlayParameterNameHints": "none", // none | literals | all "typescript.inlayHints.includeInlayParameterNameHintsWhenArgumentMatchesName": false, "typescript.inlayHints.includeInlayPropertyDeclarationTypeHints": false, "typescript.inlayHints.includeInlayVariableTypeHints": false, "typescript.inlayHints.includeInlayVariableTypeHintsWhenTypeMatchesName": false, // Code Lens options. "javascript.implementationsCodeLens.enabled": false, "javascript.referencesCodeLens.enabled": false, "javascript.referencesCodeLens.showOnAllFunctions": false, "typescript.implementationsCodeLens.enabled": false, "typescript.referencesCodeLens.enabled": false, "typescript.referencesCodeLens.showOnAllFunctions": false, }, "command": ["${node_bin}", "${server_path}", "--stdio"], "selector": "source.js, source.jsx, source.ts, source.tsx", } ```

Thanks for following up!