Language Server Protocol
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 Sandboxdaytona = Daytona()sandbox = daytona.create()
# Create LSP server for Pythonlsp_server = sandbox.create_lsp_server( language_id=LspLanguageId.PYTHON, path_to_project="workspace/project")import { Daytona, LspLanguageId } from '@daytonaio/sdk'
// Create sandboxconst daytona = new Daytona()const sandbox = await daytona.create({ language: 'typescript',})
// Create LSP server for TypeScriptconst lspServer = await sandbox.createLspServer( LspLanguageId.TYPESCRIPT, 'workspace/project')require 'daytona'
# Create Sandboxdaytona = Daytona::Daytona.newsandbox = daytona.create
# Create LSP server for Pythonlsp_server = sandbox.create_lsp_server( language_id: Daytona::LspServer::Language::PYTHON, path_to_project: 'workspace/project')// Create sandboxclient, err := daytona.NewClient()if err != nil { log.Fatal(err)}
ctx := context.Background()sandbox, err := client.Create(ctx, nil)if err != nil { log.Fatal(err)}
// Get LSP service for Pythonlsp := sandbox.Lsp(types.LspLanguagePython, "workspace/project")For more information, see the Python SDK, TypeScript SDK, Ruby SDK, and Go SDK references:
create_lsp_server (Python SDK)
Supported languages
The supported languages for creating LSP servers with Daytona are defined by the LspLanguageId enum:
| Enum Value | Description |
|---|---|
LspLanguageId.PYTHON | Python language server |
LspLanguageId.TYPESCRIPT | TypeScript/JavaScript language server |
For more information, see the Python SDK and TypeScript SDK references:
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 operationsconst lsp = await sandbox.createLspServer('typescript', 'workspace/project')await lsp.start() // Initialize the server// Now ready for LSP operationslsp = sandbox.create_lsp_server( language_id: Daytona::LspServer::Language::PYTHON, path_to_project: 'workspace/project')lsp.start # Initialize the server# Now ready for LSP operationslsp := sandbox.Lsp(types.LspLanguagePython, "workspace/project")err := lsp.Start(ctx) // Initialize the serverif err != nil { log.Fatal(err)}// Now ready for LSP operationscurl 'https://proxy.app.daytona.io/toolbox/{sandboxId}/lsp/start' \ --request POST \ --header 'Content-Type: application/json' \ --data '{ "languageId": "", "pathToProject": ""}'For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, and API references:
Stop LSP servers
Daytona provides methods to stop LSP servers.
# When done with LSP featureslsp.stop() # Clean up resources// When done with LSP featuresawait lsp.stop() // Clean up resources# When done with LSP featureslsp.stop # Clean up resources// When done with LSP featureserr := lsp.Stop(ctx) // Clean up resourcesif err != nil { log.Fatal(err)}curl 'https://proxy.app.daytona.io/toolbox/{sandboxId}/lsp/stop' \ --request POST \ --header 'Content-Type: application/json' \ --data '{ "languageId": "", "pathToProject": ""}'For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, and API references:
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}")const completions = await lspServer.completions('workspace/project/main.ts', { line: 10, character: 15,})console.log('Completions:', completions)completions = lsp_server.completions( path: 'workspace/project/main.py', position: { line: 10, character: 15 })puts "Completions: #{completions}"completions, err := lsp.Completions(ctx, "workspace/project/main.py", types.Position{Line: 10, Character: 15},)if err != nil { log.Fatal(err)}fmt.Printf("Completions: %v\n", completions)curl 'https://proxy.app.daytona.io/toolbox/{sandboxId}/lsp/completions' \ --request POST \ --header 'Content-Type: application/json' \ --data '{ "context": { "triggerCharacter": "", "triggerKind": 1 }, "languageId": "", "pathToProject": "", "position": { "character": 1, "line": 1 }, "uri": ""}'For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, and API references:
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 openlsp_server.did_open("workspace/project/main.py")// Notify server that a file is openawait lspServer.didOpen('workspace/project/main.ts')# Notify server that a file is openlsp_server.did_open('workspace/project/main.py')// Notify server that a file is openerr := lsp.DidOpen(ctx, "workspace/project/main.py")if err != nil { log.Fatal(err)}curl 'https://proxy.app.daytona.io/toolbox/{sandboxId}/lsp/did-open' \ --request POST \ --header 'Content-Type: application/json' \ --data '{ "languageId": "", "pathToProject": "", "uri": ""}'For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, and API references:
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 closedlsp_server.did_close("workspace/project/main.py")// Notify server that a file is closedawait lspServer.didClose('workspace/project/main.ts')# Notify server that a file is closedlsp_server.did_close('workspace/project/main.py')// Notify server that a file is closederr := lsp.DidClose(ctx, "workspace/project/main.py")if err != nil { log.Fatal(err)}curl 'https://proxy.app.daytona.io/toolbox/{sandboxId}/lsp/did-close' \ --request POST \ --header 'Content-Type: application/json' \ --data '{ "languageId": "", "pathToProject": "", "uri": ""}'For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, and API references:
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}")const symbols = await lspServer.documentSymbols('workspace/project/main.ts')symbols.forEach((symbol) => { console.log(`Symbol: ${symbol.name}, Kind: ${symbol.kind}`)})symbols = lsp_server.document_symbols('workspace/project/main.py')symbols.each do |symbol| puts "Symbol: #{symbol.name}, Kind: #{symbol.kind}"endsymbols, err := lsp.DocumentSymbols(ctx, "workspace/project/main.py")if err != nil { log.Fatal(err)}for _, symbol := range symbols { fmt.Printf("Symbol: %v\n", symbol)}curl 'https://proxy.app.daytona.io/toolbox/{sandboxId}/lsp/document-symbols?languageId=&pathToProject=&uri='For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, and API references:
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}")const symbols = await lspServer.sandboxSymbols('MyClass')symbols.forEach((symbol) => { console.log(`Found: ${symbol.name} at ${symbol.location}`)})symbols = lsp_server.sandbox_symbols('MyClass')symbols.each do |symbol| puts "Found: #{symbol.name} at #{symbol.location}"endsymbols, err := lsp.SandboxSymbols(ctx, "MyClass")if err != nil { log.Fatal(err)}for _, symbol := range symbols { fmt.Printf("Found: %v\n", symbol)}curl 'https://proxy.app.daytona.io/toolbox/{sandboxId}/lsp/workspacesymbols?query=&languageId=&pathToProject='For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, and API references: