-
Notifications
You must be signed in to change notification settings - Fork 13.1k
feat: add experimental support for Ty language server #5575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0ccacb9
948e8f9
71ccdd7
9bc58f3
3234e56
df5179d
ca3fd2b
83abc80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -361,6 +361,62 @@ export namespace LSPServer { | |
| }, | ||
| } | ||
|
|
||
| export const Ty: Info = { | ||
| id: "ty", | ||
| extensions: [".py", ".pyi"], | ||
| root: NearestRoot(["pyproject.toml", "ty.toml", "setup.py", "setup.cfg", "requirements.txt", "Pipfile", "pyrightconfig.json"]), | ||
| async spawn(root) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't this spawning even when the var isn't set?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh I thought the way the logic goes, the servers only get spawned at after being loaded to the But then again i could just add a check there just to be 1000% guaranteed.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just like how in if (cfg.lsp === false) {
log.info("all LSPs are disabled")
return {
broken: new Set<string>(),
servers,
clients,
spawning: new Map<string, Promise<LSPClient.Info | undefined>>(),
}
}it can return just empty servers and spawning methods |
||
| if(!Flag.OPENCODE_EXPERIMENTAL_LSP_TY) { | ||
| return undefined | ||
| } | ||
|
|
||
| let binary = Bun.which("ty") | ||
|
|
||
| const initialization: Record<string, string> = {} | ||
|
|
||
| const potentialVenvPaths = [process.env["VIRTUAL_ENV"], path.join(root, ".venv"), path.join(root, "venv")].filter( | ||
| (p): p is string => p !== undefined, | ||
| ) | ||
| for (const venvPath of potentialVenvPaths) { | ||
| const isWindows = process.platform === "win32" | ||
| const potentialPythonPath = isWindows | ||
| ? path.join(venvPath, "Scripts", "python.exe") | ||
| : path.join(venvPath, "bin", "python") | ||
| if (await Bun.file(potentialPythonPath).exists()) { | ||
| initialization["pythonPath"] = potentialPythonPath | ||
| break | ||
| } | ||
| } | ||
|
|
||
rekram1-node marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if(!binary) { | ||
| for (const venvPath of potentialVenvPaths) { | ||
| const isWindows = process.platform === "win32" | ||
| const potentialTyPath = isWindows | ||
| ? path.join(venvPath, "Scripts", "ty.exe") | ||
| : path.join(venvPath, "bin", "ty") | ||
| if (await Bun.file(potentialTyPath).exists()) { | ||
| binary = potentialTyPath | ||
| break | ||
| } | ||
| } | ||
| } | ||
|
|
||
rekram1-node marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if(!binary) { | ||
| log.error("ty not found, please install ty first") | ||
| return | ||
| } | ||
|
|
||
| const proc = spawn(binary, ["server"], { | ||
| cwd: root, | ||
| }) | ||
|
|
||
| return { | ||
| process: proc, | ||
| initialization, | ||
| } | ||
| }, | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential issue: The
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense bro-chacho |
||
| export const Pyright: Info = { | ||
| id: "pyright", | ||
| extensions: [".py", ".pyi"], | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.