Skip to content

Language Server Protocol

View as Markdown

Daytona provides Language Server Protocol (LSP) support through sandbox instances. This enables advanced language features like code completion, diagnostics, and more.

Create LSP servers

Daytona provides methods to create LSP servers. The path_to_project argument is relative to the current sandbox working directory when no leading / is used. The working directory is specified by WORKDIR when it is present in the Dockerfile, and otherwise falls back to the user’s home directory.

from daytona import Daytona, LspLanguageId
# Create Sandbox
daytona = Daytona()
sandbox = daytona.create()
# Create LSP server for Python
lsp_server = sandbox.create_lsp_server(
language_id=LspLanguageId.PYTHON,
path_to_project="workspace/project"
)

For more information, see the Python SDK, TypeScript SDK, Ruby SDK, and Go SDK references:

create_lsp_server (Python SDK)

createLspServer (TypeScript SDK)

create_lsp_server (Ruby SDK)

Supported languages

The supported languages for creating LSP servers with Daytona are defined by the LspLanguageId enum:

Enum ValueDescription
LspLanguageId.PYTHONPython language server
LspLanguageId.TYPESCRIPTTypeScript/JavaScript language server

For more information, see the Python SDK and TypeScript SDK references:

LspLanguageId (Python SDK)

LspLanguageId (TypeScript SDK)

Start LSP servers

Daytona provides methods to start LSP servers.

lsp = sandbox.create_lsp_server("typescript", "workspace/project")
lsp.start() # Initialize the server
# Now ready for LSP operations

For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, and API references:

start (Python SDK)

start (TypeScript SDK)

start (Ruby SDK)

Start (Go SDK)

start (API)

Stop LSP servers

Daytona provides methods to stop LSP servers.

# When done with LSP features
lsp.stop() # Clean up resources

For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, and API references:

stop (Python SDK)

stop (TypeScript SDK)

stop (Ruby SDK)

Stop (Go SDK)

stop (API)

Code completions

Daytona provides methods to get code completions for a specific position in a file.

completions = lsp_server.completions(
path="workspace/project/main.py",
position={"line": 10, "character": 15}
)
print(f"Completions: {completions}")

For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, and API references:

completions (Python SDK)

completions (TypeScript SDK)

completions (Ruby SDK)

Completions (Go SDK)

completions (API)

File notifications

Daytona provides methods to notify the LSP server when files are opened or closed. This enables features like diagnostics and completion tracking for the specified files.

Open file

Notifies the language server that a file has been opened for editing.

# Notify server that a file is open
lsp_server.did_open("workspace/project/main.py")

For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, and API references:

did_open (Python SDK)

didOpen (TypeScript SDK)

did_open (Ruby SDK)

DidOpen (Go SDK)

did_open (API)

Close file

Notifies the language server that a file has been closed. This allows the server to clean up resources associated with that file.

# Notify server that a file is closed
lsp_server.did_close("workspace/project/main.py")

For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, and API references:

did_close (Python SDK)

didClose (TypeScript SDK)

did_close (Ruby SDK)

DidClose (Go SDK)

did_close (API)

Document symbols

Daytona provides methods to retrieve symbols (functions, classes, variables, etc.) from a document.

symbols = lsp_server.document_symbols("workspace/project/main.py")
for symbol in symbols:
print(f"Symbol: {symbol.name}, Kind: {symbol.kind}")

For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, and API references:

document_symbols (Python SDK)

documentSymbols (TypeScript SDK)

document_symbols (Ruby SDK)

DocumentSymbols (Go SDK)

document_symbols (API)

Sandbox symbols

Daytona provides methods to search for symbols across all files in the sandbox.

symbols = lsp_server.sandbox_symbols("MyClass")
for symbol in symbols:
print(f"Found: {symbol.name} at {symbol.location}")

For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, and API references:

sandbox_symbols (Python SDK)

sandboxSymbols (TypeScript SDK)

sandbox_symbols (Ruby SDK)

SandboxSymbols (Go SDK)

sandbox_symbols (API)