Bug 495805 - LSP extension does not format .tsx files correctly.
Summary: LSP extension does not format .tsx files correctly.
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: application (other bugs)
Version First Reported In: 24.08.2
Platform: Arch Linux Linux
: NOR major
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-11-04 21:58 UTC by Majid Madadi
Modified: 2024-11-23 15:18 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Majid Madadi 2024-11-04 21:58:18 UTC
***
If you're not sure this is actually a bug, instead post about it at https://discuss.kde.org

If you're reporting a crash, attach a backtrace with debug symbols; see https://community.kde.org/Guidelines_and_HOWTOs/Debugging/How_to_create_useful_crash_reports

Please remove this comment after reading and before submitting - thanks!
***

SUMMARY


STEPS TO REPRODUCE
1. create a react app with typescript template
2. try to format one of .tsx files


SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Endeavouros
KDE Plasma Version: 6.2.2
KDE Frameworks Version: 6.7.0
Qt Version: 6.8

ADDITIONAL INFORMATION
LSP extension does not format .tsx files correctly. I have contacted the authors of LSP and they said the parameter is not passed correctly to the server.
Comment 1 Bojidar Marinov [:bojidar-bg] 2024-11-05 18:11:22 UTC
Testing locally to fix a related issue (the typescript language server highlighting all TSX tags as errors), and inspecting the messages sent to the language server, it seems like Kate sends "languageId": "typescript" instead of "languageId": "typescriptreact".

Reverting https://invent.kde.org/utilities/kate/-/merge_requests/1349 and sending no languageId, would work, since https://github.com/typescript-language-server/typescript-language-server/pull/799 made the result of that be a warning and not an error in typescript-language-server 4.1.1 and above.

However, it would seems like adding the following local LSP configuration can get things working even better, without even triggering the warning:
```
{
    "servers": {
        "javascript": {
            "highlightingModeRegex": "^JavaScript$"
        },
        "javascriptreact": {
            "use": "javascript",
            "highlightingModeRegex": "^JavaScript React.+$"
        },
        "typescript": {
            "use": "javascript",
            "highlightingModeRegex": "^TypeScript$"
        },
        "typescriptreact": {
            "use": "javascript",
            "highlightingModeRegex": "^TypeScript React.+$"
        }
    }
}
```
Comment 2 Christoph Cullmann 2024-11-06 15:30:15 UTC
If that are the proper ids, we can adapt that upstream.
Comment 3 Bojidar Marinov [:bojidar-bg] 2024-11-06 16:09:08 UTC
The LSP Specification for TextDocumentItem (https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocumentItem) has a table of recommended languageId-s, including:

Language       	Identifier
JavaScript      	javascript
JavaScript React	javascriptreact
TypeScript      	typescript
TypeScript React	typescriptreact

So yes, it would appear that those are the correct languageId-s.
Comment 4 Majid Madadi 2024-11-06 18:48:04 UTC
(In reply to Christoph Cullmann from comment #2)
> If that are the proper ids, we can adapt that upstream.

The error is gone with this config but still LSP document format does work for .tsx files.
Comment 5 Christoph Cullmann 2024-11-17 19:03:01 UTC
Git commit a40abe2cc608dca520d61e536c85a43d00848871 by Christoph Cullmann.
Committed on 17/11/2024 at 19:02.
Pushed by cullmann into branch 'master'.

fix language ids for javascript derivates

M  +10   -2    addons/lspclient/settings.json

https://invent.kde.org/utilities/kate/-/commit/a40abe2cc608dca520d61e536c85a43d00848871
Comment 6 Christoph Cullmann 2024-11-17 19:05:02 UTC
Thanks for testing this.
Comment 7 Christoph Cullmann 2024-11-23 15:18:33 UTC
Git commit 97da9d2e357b4b46cd7a6f74be654710edb06fd5 by Christoph Cullmann.
Committed on 23/11/2024 at 15:18.
Pushed by cullmann into branch 'release/24.12'.

fix language ids for javascript derivates


(cherry picked from commit a40abe2cc608dca520d61e536c85a43d00848871)

Co-authored-by: Christoph Cullmann <christoph@cullmann.io>

M  +10   -2    addons/lspclient/settings.json

https://invent.kde.org/utilities/kate/-/commit/97da9d2e357b4b46cd7a6f74be654710edb06fd5