Skip to content

feat(lsp): add shebang-based language detection#15519

Open
manicolosi wants to merge 1 commit intoanomalyco:devfrom
manicolosi:feat/shebang-lsp-detection
Open

feat(lsp): add shebang-based language detection#15519
manicolosi wants to merge 1 commit intoanomalyco:devfrom
manicolosi:feat/shebang-lsp-detection

Conversation

@manicolosi
Copy link

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)

Issue for this PR

Closes #15518

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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?

  1. Added test cases.
  2. Tested locally (via bun run dev) and asked OpenCode to read a script with no extension and verified the LSP status showed connected to pywright. Also observed diagnostics being output when the read tool was used. Previously this did not work unless the file had an extension.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

If you do not follow this template your PR will be automatically rejected.

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Support LSP detection via shebang line for extensionless scripts

1 participant