Class: Daytona::LspServer

Inherits:
Object
  • Object
show all
Includes:
Instrumentation
Defined in:
lib/daytona/lsp_server.rb

Defined Under Namespace

Modules: Language Classes: Position

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Instrumentation

included

Constructor Details

#initialize(language_id:, path_to_project:, toolbox_api:, sandbox_id:, otel_state: nil) ⇒ LspServer

Returns a new instance of LspServer.

Parameters:

  • language_id (Symbol)
  • path_to_project (String)
  • toolbox_api (DaytonaToolboxApiClient::LspApi)
  • sandbox_id (String)
  • otel_state (Daytona::OtelState, nil) (defaults to: nil)


40
41
42
43
44
45
46
# File 'lib/daytona/lsp_server.rb', line 40

def initialize(language_id:, path_to_project:, toolbox_api:, sandbox_id:, otel_state: nil)
  @language_id = language_id
  @path_to_project = path_to_project
  @toolbox_api = toolbox_api
  @sandbox_id = sandbox_id
  @otel_state = otel_state
end

Instance Attribute Details

#language_idSymbol (readonly)

Returns:

  • (Symbol)


24
25
26
# File 'lib/daytona/lsp_server.rb', line 24

def language_id
  @language_id
end

#path_to_projectString (readonly)

Returns:

  • (String)


27
28
29
# File 'lib/daytona/lsp_server.rb', line 27

def path_to_project
  @path_to_project
end

#sandbox_idString (readonly)

Returns:

  • (String)


33
34
35
# File 'lib/daytona/lsp_server.rb', line 33

def sandbox_id
  @sandbox_id
end

#toolbox_apiDaytonaToolboxApiClient::LspApi (readonly)

Returns:

  • (DaytonaToolboxApiClient::LspApi)


30
31
32
# File 'lib/daytona/lsp_server.rb', line 30

def toolbox_api
  @toolbox_api
end

Instance Method Details

#completions(path:, position:) ⇒ DaytonaApiClient::CompletionList

Gets completion suggestions at a position in a file

Parameters:

Returns:

  • (DaytonaApiClient::CompletionList)


53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/daytona/lsp_server.rb', line 53

def completions(path:, position:)
  toolbox_api.completions(
    DaytonaToolboxApiClient::LspCompletionParams.new(
      language_id:,
      path_to_project:,
      uri: uri(path),
      position: DaytonaApiClient::Position.new(line: position.line, character: position.character)
    )
  )
rescue *Sdk::API_ERROR_CLASSES => e
  raise Sdk.wrap_error(e, 'Failed to get LSP completions')
end

#did_close(path) ⇒ void

This method returns an undefined value.

Notify the language server that a file has been closed. This method should be called when a file is closed in the editor to allow the language server to clean up any resources associated with that file.

Parameters:

  • path (String)


72
73
74
75
76
77
78
# File 'lib/daytona/lsp_server.rb', line 72

def did_close(path)
  toolbox_api.did_close(
    DaytonaToolboxApiClient::LspDocumentRequest.new(language_id:, path_to_project:, uri: uri(path))
  )
rescue *Sdk::API_ERROR_CLASSES => e
  raise Sdk.wrap_error(e, 'Failed to notify LSP server of closed document')
end

#did_open(path) ⇒ void

This method returns an undefined value.

Notifies the language server that a file has been opened. This method should be called when a file is opened in the editor to enable language features like diagnostics and completions for that file. The server will begin tracking the file’s contents and providing language features.

Parameters:

  • path (String)


87
88
89
90
91
92
93
# File 'lib/daytona/lsp_server.rb', line 87

def did_open(path)
  toolbox_api.did_open(
    DaytonaToolboxApiClient::LspDocumentRequest.new(language_id:, path_to_project:, uri: uri(path))
  )
rescue *Sdk::API_ERROR_CLASSES => e
  raise Sdk.wrap_error(e, 'Failed to notify LSP server of opened document')
end

#document_symbols(path) ⇒ Array<DaytonaToolboxApiClient::LspSymbol]

Gets symbol information (functions, classes, variables, etc.) from a document.

Parameters:

  • path (String)

Returns:

  • (Array<DaytonaToolboxApiClient::LspSymbol])

    Array<DaytonaToolboxApiClient::LspSymbol]



99
100
101
102
103
# File 'lib/daytona/lsp_server.rb', line 99

def document_symbols(path)
  toolbox_api.document_symbols(language_id, path_to_project, uri(path))
rescue *Sdk::API_ERROR_CLASSES => e
  raise Sdk.wrap_error(e, 'Failed to get LSP document symbols')
end

#sandbox_symbols(query) ⇒ Array<DaytonaToolboxApiClient::LspSymbol]

Searches for symbols matching the query string across all files in the Sandbox.

Parameters:

  • query (String)

Returns:

  • (Array<DaytonaToolboxApiClient::LspSymbol])

    Array<DaytonaToolboxApiClient::LspSymbol]



110
111
112
113
114
# File 'lib/daytona/lsp_server.rb', line 110

def sandbox_symbols(query)
  toolbox_api.workspace_symbols(query, language_id, path_to_project)
rescue *Sdk::API_ERROR_CLASSES => e
  raise Sdk.wrap_error(e, 'Failed to get LSP workspace symbols')
end

#startvoid

This method returns an undefined value.

Starts the language server. This method must be called before using any other LSP functionality. It initializes the language server for the specified language and project.



121
122
123
124
125
126
127
# File 'lib/daytona/lsp_server.rb', line 121

def start
  toolbox_api.start(
    DaytonaToolboxApiClient::LspServerRequest.new(language_id:, path_to_project:)
  )
rescue *Sdk::API_ERROR_CLASSES => e
  raise Sdk.wrap_error(e, 'Failed to start LSP server')
end

#stopvoid

This method returns an undefined value.

Stops the language server. This method should be called when the LSP server is no longer needed to free up system resources.



134
135
136
137
138
139
140
# File 'lib/daytona/lsp_server.rb', line 134

def stop
  toolbox_api.stop(
    DaytonaToolboxApiClient::LspServerRequest.new(language_id:, path_to_project:)
  )
rescue *Sdk::API_ERROR_CLASSES => e
  raise Sdk.wrap_error(e, 'Failed to stop LSP server')
end