feat(lsp): add shebang-based language detection#15519
Open
manicolosi wants to merge 1 commit intoanomalyco:devfrom
Open
feat(lsp): add shebang-based language detection#15519manicolosi wants to merge 1 commit intoanomalyco:devfrom
manicolosi wants to merge 1 commit intoanomalyco:devfrom
Conversation
Adds support for detecting language from shebang line when file has no recognized extension. Useful for PEP 723 scripts using uv run --script. Changes: - lsp/language.ts: Add SHEBANG_PATTERNS and getLanguageFromShebang() - lsp/server.ts: Add shebangs property to server definitions - lsp/index.ts: Use shebang as fallback when extension doesn't match - lsp/client.ts: Use shebang for languageId when extension is unknown - Add unit tests in test/lsp/language.test.ts - Update docs (en, zh-cn, zh-tw, de)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes:
lsp/language.ts: AddSHEBANG_PATTERNSandgetLanguageFromShebang()lsp/server.ts: Add shebangs property to server definitionslsp/index.ts: Use shebang as fallback when extension doesn't matchlsp/client.ts: Use shebang forlanguageIdwhen extension is unknowntest/lsp/language.test.tsIssue for this PR
Closes #15518
Type of change
What does this PR do?
I noticed that LSP support was only working for files with extensions (e.g.
.py), but I'm working on a script without an extension. This PR adds support for parsing shebang lines when there's no extension available.Disclaimer: I have little experience with this codebase and typescript. The changes seem simple enough and have worked for me in practice.
How did you verify your code works?
bun run dev) and asked OpenCode to read a script with no extension and verified the LSP status showed connected topywright. Also observed diagnostics being output when the read tool was used. Previously this did not work unless the file had an extension.Checklist
If you do not follow this template your PR will be automatically rejected.