@daytonaio/sdk 0.9.2 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/dist/Daytona.d.ts +239 -47
  2. package/dist/Daytona.js +274 -63
  3. package/dist/FileSystem.d.ts +183 -32
  4. package/dist/FileSystem.js +168 -28
  5. package/dist/Git.d.ts +178 -30
  6. package/dist/Git.js +178 -30
  7. package/dist/LspServer.d.ts +170 -22
  8. package/dist/LspServer.js +162 -18
  9. package/dist/Process.d.ts +187 -37
  10. package/dist/Process.js +185 -44
  11. package/dist/Workspace.d.ts +252 -36
  12. package/dist/Workspace.js +239 -49
  13. package/dist/code-toolbox/WorkspacePythonCodeToolbox.d.ts +2 -1
  14. package/dist/code-toolbox/WorkspacePythonCodeToolbox.js +4 -2
  15. package/dist/code-toolbox/WorkspaceTsCodeToolbox.d.ts +2 -1
  16. package/dist/code-toolbox/WorkspaceTsCodeToolbox.js +4 -2
  17. package/dist/errors/DaytonaError.d.ts +8 -0
  18. package/dist/errors/DaytonaError.js +12 -0
  19. package/dist/index.d.ts +4 -0
  20. package/dist/index.js +12 -1
  21. package/dist/utils/Axios.d.ts +6 -0
  22. package/dist/utils/Axios.js +28 -0
  23. package/dist/utils/errors.d.ts +10 -0
  24. package/dist/utils/errors.js +36 -0
  25. package/dist/utils/timeout.d.ts +35 -0
  26. package/dist/utils/timeout.js +73 -0
  27. package/package.json +9 -8
  28. package/dist/client/apis/ApiKeyApi.d.ts +0 -54
  29. package/dist/client/apis/ApiKeyApi.js +0 -135
  30. package/dist/client/apis/BuildApi.d.ts +0 -95
  31. package/dist/client/apis/BuildApi.js +0 -228
  32. package/dist/client/apis/ContainerRegistryApi.d.ts +0 -68
  33. package/dist/client/apis/ContainerRegistryApi.js +0 -163
  34. package/dist/client/apis/DefaultApi.d.ts +0 -31
  35. package/dist/client/apis/DefaultApi.js +0 -72
  36. package/dist/client/apis/GitProviderApi.d.ts +0 -197
  37. package/dist/client/apis/GitProviderApi.js +0 -477
  38. package/dist/client/apis/PrebuildApi.d.ts +0 -97
  39. package/dist/client/apis/PrebuildApi.js +0 -241
  40. package/dist/client/apis/ProfileApi.d.ts +0 -51
  41. package/dist/client/apis/ProfileApi.js +0 -128
  42. package/dist/client/apis/ProjectConfigApi.d.ts +0 -94
  43. package/dist/client/apis/ProjectConfigApi.js +0 -220
  44. package/dist/client/apis/ProviderApi.d.ts +0 -71
  45. package/dist/client/apis/ProviderApi.js +0 -160
  46. package/dist/client/apis/SampleApi.d.ts +0 -28
  47. package/dist/client/apis/SampleApi.js +0 -73
  48. package/dist/client/apis/ServerApi.d.ts +0 -61
  49. package/dist/client/apis/ServerApi.js +0 -156
  50. package/dist/client/apis/TargetApi.d.ts +0 -67
  51. package/dist/client/apis/TargetApi.js +0 -159
  52. package/dist/client/apis/WorkspaceApi.d.ts +0 -141
  53. package/dist/client/apis/WorkspaceApi.js +0 -330
  54. package/dist/client/apis/WorkspaceToolboxApi.d.ts +0 -464
  55. package/dist/client/apis/WorkspaceToolboxApi.js +0 -1248
  56. package/dist/client/apis/index.d.ts +0 -14
  57. package/dist/client/apis/index.js +0 -32
  58. package/dist/client/index.d.ts +0 -3
  59. package/dist/client/index.js +0 -21
  60. package/dist/client/models/ApiKey.d.ts +0 -45
  61. package/dist/client/models/ApiKey.js +0 -60
  62. package/dist/client/models/ApikeyApiKeyType.d.ts +0 -26
  63. package/dist/client/models/ApikeyApiKeyType.js +0 -52
  64. package/dist/client/models/Build.d.ts +0 -98
  65. package/dist/client/models/Build.js +0 -91
  66. package/dist/client/models/BuildBuildState.d.ts +0 -31
  67. package/dist/client/models/BuildBuildState.js +0 -57
  68. package/dist/client/models/BuildConfig.d.ts +0 -40
  69. package/dist/client/models/BuildConfig.js +0 -57
  70. package/dist/client/models/CachedBuild.d.ts +0 -38
  71. package/dist/client/models/CachedBuild.js +0 -55
  72. package/dist/client/models/CloneTarget.d.ts +0 -25
  73. package/dist/client/models/CloneTarget.js +0 -51
  74. package/dist/client/models/CompletionContext.d.ts +0 -38
  75. package/dist/client/models/CompletionContext.js +0 -53
  76. package/dist/client/models/CompletionItem.d.ts +0 -68
  77. package/dist/client/models/CompletionItem.js +0 -63
  78. package/dist/client/models/CompletionList.d.ts +0 -39
  79. package/dist/client/models/CompletionList.js +0 -56
  80. package/dist/client/models/ContainerConfig.d.ts +0 -38
  81. package/dist/client/models/ContainerConfig.js +0 -55
  82. package/dist/client/models/ContainerRegistry.d.ts +0 -44
  83. package/dist/client/models/ContainerRegistry.js +0 -59
  84. package/dist/client/models/CreateBuildDTO.d.ts +0 -52
  85. package/dist/client/models/CreateBuildDTO.js +0 -62
  86. package/dist/client/models/CreatePrebuildDTO.d.ts +0 -56
  87. package/dist/client/models/CreatePrebuildDTO.js +0 -59
  88. package/dist/client/models/CreateProjectConfigDTO.d.ts +0 -71
  89. package/dist/client/models/CreateProjectConfigDTO.js +0 -72
  90. package/dist/client/models/CreateProjectDTO.d.ts +0 -72
  91. package/dist/client/models/CreateProjectDTO.js +0 -73
  92. package/dist/client/models/CreateProjectSourceDTO.d.ts +0 -33
  93. package/dist/client/models/CreateProjectSourceDTO.js +0 -52
  94. package/dist/client/models/CreateProviderTargetDTO.d.ts +0 -45
  95. package/dist/client/models/CreateProviderTargetDTO.js +0 -60
  96. package/dist/client/models/CreateWorkspaceDTO.d.ts +0 -51
  97. package/dist/client/models/CreateWorkspaceDTO.js +0 -64
  98. package/dist/client/models/DevcontainerConfig.d.ts +0 -32
  99. package/dist/client/models/DevcontainerConfig.js +0 -51
  100. package/dist/client/models/ExecuteRequest.d.ts +0 -38
  101. package/dist/client/models/ExecuteRequest.js +0 -53
  102. package/dist/client/models/ExecuteResponse.d.ts +0 -38
  103. package/dist/client/models/ExecuteResponse.js +0 -55
  104. package/dist/client/models/FRPSConfig.d.ts +0 -44
  105. package/dist/client/models/FRPSConfig.js +0 -59
  106. package/dist/client/models/FileInfo.d.ts +0 -74
  107. package/dist/client/models/FileInfo.js +0 -79
  108. package/dist/client/models/FileStatus.d.ts +0 -51
  109. package/dist/client/models/FileStatus.js +0 -64
  110. package/dist/client/models/GetRepositoryContext.d.ts +0 -80
  111. package/dist/client/models/GetRepositoryContext.js +0 -67
  112. package/dist/client/models/GitAddRequest.d.ts +0 -38
  113. package/dist/client/models/GitAddRequest.js +0 -55
  114. package/dist/client/models/GitBranch.d.ts +0 -38
  115. package/dist/client/models/GitBranch.js +0 -55
  116. package/dist/client/models/GitBranchRequest.d.ts +0 -38
  117. package/dist/client/models/GitBranchRequest.js +0 -55
  118. package/dist/client/models/GitCloneRequest.d.ts +0 -62
  119. package/dist/client/models/GitCloneRequest.js +0 -63
  120. package/dist/client/models/GitCommitInfo.d.ts +0 -56
  121. package/dist/client/models/GitCommitInfo.js +0 -67
  122. package/dist/client/models/GitCommitRequest.d.ts +0 -50
  123. package/dist/client/models/GitCommitRequest.js +0 -63
  124. package/dist/client/models/GitCommitResponse.d.ts +0 -32
  125. package/dist/client/models/GitCommitResponse.js +0 -51
  126. package/dist/client/models/GitNamespace.d.ts +0 -38
  127. package/dist/client/models/GitNamespace.js +0 -55
  128. package/dist/client/models/GitProvider.d.ts +0 -75
  129. package/dist/client/models/GitProvider.js +0 -76
  130. package/dist/client/models/GitPullRequest.d.ts +0 -68
  131. package/dist/client/models/GitPullRequest.js +0 -75
  132. package/dist/client/models/GitRepoRequest.d.ts +0 -44
  133. package/dist/client/models/GitRepoRequest.js +0 -55
  134. package/dist/client/models/GitRepository.d.ts +0 -87
  135. package/dist/client/models/GitRepository.js +0 -84
  136. package/dist/client/models/GitStatus.d.ts +0 -57
  137. package/dist/client/models/GitStatus.js +0 -62
  138. package/dist/client/models/GitUser.d.ts +0 -50
  139. package/dist/client/models/GitUser.js +0 -63
  140. package/dist/client/models/InstallProviderRequest.d.ts +0 -40
  141. package/dist/client/models/InstallProviderRequest.js +0 -55
  142. package/dist/client/models/ListBranchResponse.d.ts +0 -32
  143. package/dist/client/models/ListBranchResponse.js +0 -51
  144. package/dist/client/models/LogFileConfig.d.ts +0 -62
  145. package/dist/client/models/LogFileConfig.js +0 -67
  146. package/dist/client/models/LspCompletionParams.d.ts +0 -58
  147. package/dist/client/models/LspCompletionParams.js +0 -69
  148. package/dist/client/models/LspDocumentRequest.d.ts +0 -44
  149. package/dist/client/models/LspDocumentRequest.js +0 -59
  150. package/dist/client/models/LspLocation.d.ts +0 -39
  151. package/dist/client/models/LspLocation.js +0 -56
  152. package/dist/client/models/LspPosition.d.ts +0 -38
  153. package/dist/client/models/LspPosition.js +0 -55
  154. package/dist/client/models/LspRange.d.ts +0 -39
  155. package/dist/client/models/LspRange.js +0 -56
  156. package/dist/client/models/LspServerRequest.d.ts +0 -38
  157. package/dist/client/models/LspServerRequest.js +0 -55
  158. package/dist/client/models/LspSymbol.d.ts +0 -45
  159. package/dist/client/models/LspSymbol.js +0 -60
  160. package/dist/client/models/Match.d.ts +0 -44
  161. package/dist/client/models/Match.js +0 -59
  162. package/dist/client/models/NetworkKey.d.ts +0 -32
  163. package/dist/client/models/NetworkKey.js +0 -51
  164. package/dist/client/models/Position.d.ts +0 -38
  165. package/dist/client/models/Position.js +0 -55
  166. package/dist/client/models/PrebuildConfig.d.ts +0 -56
  167. package/dist/client/models/PrebuildConfig.js +0 -67
  168. package/dist/client/models/PrebuildDTO.d.ts +0 -62
  169. package/dist/client/models/PrebuildDTO.js +0 -68
  170. package/dist/client/models/ProfileData.d.ts +0 -34
  171. package/dist/client/models/ProfileData.js +0 -51
  172. package/dist/client/models/Project.d.ts +0 -91
  173. package/dist/client/models/Project.js +0 -88
  174. package/dist/client/models/ProjectConfig.d.ts +0 -84
  175. package/dist/client/models/ProjectConfig.js +0 -87
  176. package/dist/client/models/ProjectDirResponse.d.ts +0 -32
  177. package/dist/client/models/ProjectDirResponse.js +0 -49
  178. package/dist/client/models/ProjectInfo.d.ts +0 -56
  179. package/dist/client/models/ProjectInfo.js +0 -65
  180. package/dist/client/models/ProjectState.d.ts +0 -45
  181. package/dist/client/models/ProjectState.js +0 -60
  182. package/dist/client/models/Provider.d.ts +0 -44
  183. package/dist/client/models/Provider.js +0 -57
  184. package/dist/client/models/ProviderProviderInfo.d.ts +0 -44
  185. package/dist/client/models/ProviderProviderInfo.js +0 -57
  186. package/dist/client/models/ProviderProviderTargetProperty.d.ts +0 -72
  187. package/dist/client/models/ProviderProviderTargetProperty.js +0 -64
  188. package/dist/client/models/ProviderProviderTargetPropertyType.d.ts +0 -29
  189. package/dist/client/models/ProviderProviderTargetPropertyType.js +0 -55
  190. package/dist/client/models/ProviderTarget.d.ts +0 -51
  191. package/dist/client/models/ProviderTarget.js +0 -64
  192. package/dist/client/models/ReplaceRequest.d.ts +0 -44
  193. package/dist/client/models/ReplaceRequest.js +0 -59
  194. package/dist/client/models/ReplaceResult.d.ts +0 -44
  195. package/dist/client/models/ReplaceResult.js +0 -53
  196. package/dist/client/models/RepositoryUrl.d.ts +0 -32
  197. package/dist/client/models/RepositoryUrl.js +0 -51
  198. package/dist/client/models/Sample.d.ts +0 -44
  199. package/dist/client/models/Sample.js +0 -59
  200. package/dist/client/models/SearchFilesResponse.d.ts +0 -32
  201. package/dist/client/models/SearchFilesResponse.js +0 -51
  202. package/dist/client/models/ServerConfig.d.ts +0 -130
  203. package/dist/client/models/ServerConfig.js +0 -119
  204. package/dist/client/models/SetGitProviderConfig.d.ts +0 -75
  205. package/dist/client/models/SetGitProviderConfig.js +0 -70
  206. package/dist/client/models/SetProjectState.d.ts +0 -39
  207. package/dist/client/models/SetProjectState.js +0 -56
  208. package/dist/client/models/SigningMethod.d.ts +0 -25
  209. package/dist/client/models/SigningMethod.js +0 -51
  210. package/dist/client/models/Status.d.ts +0 -31
  211. package/dist/client/models/Status.js +0 -57
  212. package/dist/client/models/Workspace.d.ts +0 -51
  213. package/dist/client/models/Workspace.js +0 -64
  214. package/dist/client/models/WorkspaceDTO.d.ts +0 -58
  215. package/dist/client/models/WorkspaceDTO.js +0 -67
  216. package/dist/client/models/WorkspaceInfo.d.ts +0 -45
  217. package/dist/client/models/WorkspaceInfo.js +0 -58
  218. package/dist/client/models/index.d.ts +0 -79
  219. package/dist/client/models/index.js +0 -97
  220. package/dist/client/runtime.d.ts +0 -182
  221. package/dist/client/runtime.js +0 -340
@@ -1,12 +1,67 @@
1
- import { CompletionList, LspSymbol, Workspace as WorkspaceInstance, ToolboxApi } from '@daytonaio/api-client';
2
1
  /**
3
- * Supported language server types
4
- * @typedef {('typescript')} LspLanguageId
2
+ * The Daytona SDK provides Language Server Protocol (LSP) support through Sandbox instances.
3
+ * This enables advanced language features like code completion, diagnostics, and more.
4
+ *
5
+ * The LSP server must be started with start() before using any other methods,
6
+ * and should be stopped with stop() when no longer needed to free resources.
7
+ *
8
+ * @module LspServer
9
+ *
10
+ * @example
11
+ * // Basic LSP server usage
12
+ * // Create and initialize workspace
13
+ * const workspace = await daytona.create();
14
+ *
15
+ * // Create and start LSP server
16
+ * const lsp = workspace.createLspServer('typescript', '/workspace/project');
17
+ * await lsp.start();
18
+ *
19
+ * // Open a file for editing
20
+ * await lsp.didOpen('/workspace/project/src/index.ts');
21
+ *
22
+ * // Get completions at a position
23
+ * const completions = await lsp.completions(
24
+ * '/workspace/project/src/index.ts',
25
+ * { line: 10, character: 15 }
26
+ * );
27
+ * console.log('Completions:', completions);
28
+ *
29
+ * // Get document symbols
30
+ * const symbols = await lsp.documentSymbols('/workspace/project/src/index.ts');
31
+ * symbols.forEach(symbol => {
32
+ * console.log(`${symbol.name}: ${symbol.kind}`);
33
+ * });
34
+ *
35
+ * // Clean up
36
+ * await lsp.didClose('/workspace/project/src/index.ts');
37
+ * await lsp.stop();
38
+ *
5
39
  */
6
- export type LspLanguageId = 'typescript';
40
+ import { CompletionList, LspSymbol, ToolboxApi } from '@daytonaio/api-client';
41
+ import { WorkspaceInstance } from './Workspace';
7
42
  /**
8
- * Position in a text document
43
+ * Supported language server types.
44
+ */
45
+ export declare enum LspLanguageId {
46
+ PYTHON = "python",
47
+ TYPESCRIPT = "typescript",
48
+ JAVASCRIPT = "javascript"
49
+ }
50
+ /**
51
+ * Represents a position in a text document.
52
+ *
53
+ * This interface represents a zero-based position within a text document,
54
+ * specified by line number and character offset.
55
+ *
9
56
  * @interface Position
57
+ * @property {number} line - Zero-based line number in the document
58
+ * @property {number} character - Zero-based character offset on the line
59
+ *
60
+ * @example
61
+ * const position: Position = {
62
+ * line: 10, // Line 11 (zero-based)
63
+ * character: 15 // Character 16 on the line (zero-based)
64
+ * };
10
65
  */
11
66
  export type Position = {
12
67
  /** Zero-based line number */
@@ -15,8 +70,17 @@ export type Position = {
15
70
  character: number;
16
71
  };
17
72
  /**
18
- * Provides Language Server Protocol (LSP) functionality
73
+ * Provides Language Server Protocol functionality for code intelligence.
74
+ *
75
+ * This class implements a subset of the Language Server Protocol (LSP) to provide
76
+ * IDE-like features such as code completion, symbol search, and more.
77
+ *
19
78
  * @class LspServer
79
+ *
80
+ * @property {LspLanguageId} languageId - The language server type (e.g., "typescript")
81
+ * @property {string} pathToProject - Absolute path to the project root directory
82
+ * @property {ToolboxApi} toolboxApi - API client for Sandbox operations
83
+ * @property {WorkspaceInstance} instance - The Sandbox instance this server belongs to
20
84
  */
21
85
  export declare class LspServer {
22
86
  private readonly languageId;
@@ -25,44 +89,128 @@ export declare class LspServer {
25
89
  private readonly instance;
26
90
  constructor(languageId: LspLanguageId, pathToProject: string, toolboxApi: ToolboxApi, instance: WorkspaceInstance);
27
91
  /**
28
- * Starts the language server
92
+ * Starts the language server.
93
+ *
94
+ * This method must be called before using any other LSP functionality.
95
+ * It initializes the language server for the specified language and project.
96
+ *
29
97
  * @returns {Promise<void>}
98
+ *
99
+ * @example
100
+ * const lsp = workspace.createLspServer('typescript', '/workspace/project');
101
+ * await lsp.start(); // Initialize the server
102
+ * // Now ready for LSP operations
30
103
  */
31
104
  start(): Promise<void>;
32
105
  /**
33
- * Stops the language server
106
+ * Stops the language server.
107
+ *
108
+ * This method should be called when the LSP server is no longer needed to
109
+ * free up system resources.
110
+ *
34
111
  * @returns {Promise<void>}
112
+ *
113
+ * @example
114
+ * // When done with LSP features
115
+ * await lsp.stop(); // Clean up resources
35
116
  */
36
117
  stop(): Promise<void>;
37
118
  /**
38
- * Notifies the server that a file has been opened
39
- * @param {string} path - Path to the opened file
119
+ * Notifies the language server that a file has been opened.
120
+ *
121
+ * This method should be called when a file is opened in the editor to enable
122
+ * language features like diagnostics and completions for that file. The server
123
+ * will begin tracking the file's contents and providing language features.
124
+ *
125
+ * @param {string} path - Absolute path to the opened file
40
126
  * @returns {Promise<void>}
127
+ *
128
+ * @example
129
+ * // When opening a file for editing
130
+ * await lsp.didOpen('/workspace/project/src/index.ts');
131
+ * // Now can get completions, symbols, etc. for this file
41
132
  */
42
133
  didOpen(path: string): Promise<void>;
43
134
  /**
44
- * Notifies the server that a file has been closed
45
- * @param {string} path - Path to the closed file
135
+ * Notifies the language server that a file has been closed.
136
+ *
137
+ * This method should be called when a file is closed in the editor to allow
138
+ * the language server to clean up any resources associated with that file.
139
+ *
140
+ * @param {string} path - Absolute path to the closed file
46
141
  * @returns {Promise<void>}
142
+ *
143
+ * @example
144
+ * // When done editing a file
145
+ * await lsp.didClose('/workspace/project/src/index.ts');
47
146
  */
48
147
  didClose(path: string): Promise<void>;
49
148
  /**
50
- * Gets document symbols (functions, classes, etc.)
51
- * @param {string} path - Path to the file
52
- * @returns {Promise<LspSymbol[]>} Array of document symbols
149
+ * Get symbol information from a document.
150
+ *
151
+ * This method returns information about all symbols (functions, classes,
152
+ * variables, etc.) defined in the specified document.
153
+ *
154
+ * @param {string} path - Absolute path to the file to get symbols from
155
+ * @returns {Promise<LspSymbol[]>} List of symbols in the document. Each symbol includes:
156
+ * - name: The symbol's name
157
+ * - kind: The symbol's kind (function, class, variable, etc.)
158
+ * - location: The location of the symbol in the file
159
+ *
160
+ * @example
161
+ * // Get all symbols in a file
162
+ * const symbols = await lsp.documentSymbols('/workspace/project/src/index.ts');
163
+ * symbols.forEach(symbol => {
164
+ * console.log(`${symbol.kind} ${symbol.name}: ${symbol.location}`);
165
+ * });
53
166
  */
54
167
  documentSymbols(path: string): Promise<LspSymbol[]>;
55
168
  /**
56
- * Searches for symbols across the workspace
57
- * @param {string} query - Search query
58
- * @returns {Promise<LspSymbol[]>} Array of matching symbols
169
+ * Searches for symbols across the entire Sandbox.
170
+ *
171
+ * This method searches for symbols matching the query string across all files
172
+ * in the Sandbox. It's useful for finding declarations and definitions
173
+ * without knowing which file they're in.
174
+ *
175
+ * @param {string} query - Search query to match against symbol names
176
+ * @returns {Promise<LspSymbol[]>} List of matching symbols from all files. Each symbol includes:
177
+ * - name: The symbol's name
178
+ * - kind: The symbol's kind (function, class, variable, etc.)
179
+ * - location: The location of the symbol in the file
180
+ *
181
+ * @example
182
+ * // Search for all symbols containing "User"
183
+ * const symbols = await lsp.workspaceSymbols('User');
184
+ * symbols.forEach(symbol => {
185
+ * console.log(`${symbol.name} (${symbol.kind}) in ${symbol.location}`);
186
+ * });
59
187
  */
60
188
  workspaceSymbols(query: string): Promise<LspSymbol[]>;
61
189
  /**
62
- * Gets code completion suggestions
63
- * @param {string} path - Path to the file
64
- * @param {Position} position - Cursor position
65
- * @returns {Promise<CompletionList>} List of completion suggestions
190
+ * Gets completion suggestions at a position in a file.
191
+ *
192
+ * @param {string} path - Absolute path to the file
193
+ * @param {Position} position - The position in the file where completion was requested
194
+ * @returns {Promise<CompletionList>} List of completion suggestions. The list includes:
195
+ * - isIncomplete: Whether more items might be available
196
+ * - items: List of completion items, each containing:
197
+ * - label: The text to insert
198
+ * - kind: The kind of completion
199
+ * - detail: Additional details about the item
200
+ * - documentation: Documentation for the item
201
+ * - sortText: Text used to sort the item in the list
202
+ * - filterText: Text used to filter the item
203
+ * - insertText: The actual text to insert (if different from label)
204
+ *
205
+ * @example
206
+ * // Get completions at a specific position
207
+ * const completions = await lsp.completions('/workspace/project/src/index.ts', {
208
+ * line: 10,
209
+ * character: 15
210
+ * });
211
+ * completions.items.forEach(item => {
212
+ * console.log(`${item.label} (${item.kind}): ${item.detail}`);
213
+ * });
66
214
  */
67
215
  completions(path: string, position: Position): Promise<CompletionList>;
68
216
  }
package/dist/LspServer.js CHANGED
@@ -1,9 +1,66 @@
1
1
  "use strict";
2
+ /**
3
+ * The Daytona SDK provides Language Server Protocol (LSP) support through Sandbox instances.
4
+ * This enables advanced language features like code completion, diagnostics, and more.
5
+ *
6
+ * The LSP server must be started with start() before using any other methods,
7
+ * and should be stopped with stop() when no longer needed to free resources.
8
+ *
9
+ * @module LspServer
10
+ *
11
+ * @example
12
+ * // Basic LSP server usage
13
+ * // Create and initialize workspace
14
+ * const workspace = await daytona.create();
15
+ *
16
+ * // Create and start LSP server
17
+ * const lsp = workspace.createLspServer('typescript', '/workspace/project');
18
+ * await lsp.start();
19
+ *
20
+ * // Open a file for editing
21
+ * await lsp.didOpen('/workspace/project/src/index.ts');
22
+ *
23
+ * // Get completions at a position
24
+ * const completions = await lsp.completions(
25
+ * '/workspace/project/src/index.ts',
26
+ * { line: 10, character: 15 }
27
+ * );
28
+ * console.log('Completions:', completions);
29
+ *
30
+ * // Get document symbols
31
+ * const symbols = await lsp.documentSymbols('/workspace/project/src/index.ts');
32
+ * symbols.forEach(symbol => {
33
+ * console.log(`${symbol.name}: ${symbol.kind}`);
34
+ * });
35
+ *
36
+ * // Clean up
37
+ * await lsp.didClose('/workspace/project/src/index.ts');
38
+ * await lsp.stop();
39
+ *
40
+ */
2
41
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LspServer = void 0;
42
+ exports.LspServer = exports.LspLanguageId = void 0;
43
+ /**
44
+ * Supported language server types.
45
+ */
46
+ var LspLanguageId;
47
+ (function (LspLanguageId) {
48
+ LspLanguageId["PYTHON"] = "python";
49
+ LspLanguageId["TYPESCRIPT"] = "typescript";
50
+ LspLanguageId["JAVASCRIPT"] = "javascript";
51
+ })(LspLanguageId || (exports.LspLanguageId = LspLanguageId = {}));
4
52
  /**
5
- * Provides Language Server Protocol (LSP) functionality
53
+ * Provides Language Server Protocol functionality for code intelligence.
54
+ *
55
+ * This class implements a subset of the Language Server Protocol (LSP) to provide
56
+ * IDE-like features such as code completion, symbol search, and more.
57
+ *
6
58
  * @class LspServer
59
+ *
60
+ * @property {LspLanguageId} languageId - The language server type (e.g., "typescript")
61
+ * @property {string} pathToProject - Absolute path to the project root directory
62
+ * @property {ToolboxApi} toolboxApi - API client for Sandbox operations
63
+ * @property {WorkspaceInstance} instance - The Sandbox instance this server belongs to
7
64
  */
8
65
  class LspServer {
9
66
  constructor(languageId, pathToProject, toolboxApi, instance) {
@@ -11,10 +68,22 @@ class LspServer {
11
68
  this.pathToProject = pathToProject;
12
69
  this.toolboxApi = toolboxApi;
13
70
  this.instance = instance;
71
+ if (!Object.values(LspLanguageId).includes(this.languageId)) {
72
+ throw new Error(`Invalid languageId: ${this.languageId}. Supported values are: ${Object.values(LspLanguageId).join(', ')}`);
73
+ }
14
74
  }
15
75
  /**
16
- * Starts the language server
76
+ * Starts the language server.
77
+ *
78
+ * This method must be called before using any other LSP functionality.
79
+ * It initializes the language server for the specified language and project.
80
+ *
17
81
  * @returns {Promise<void>}
82
+ *
83
+ * @example
84
+ * const lsp = workspace.createLspServer('typescript', '/workspace/project');
85
+ * await lsp.start(); // Initialize the server
86
+ * // Now ready for LSP operations
18
87
  */
19
88
  async start() {
20
89
  await this.toolboxApi.lspStart(this.instance.id, {
@@ -23,8 +92,16 @@ class LspServer {
23
92
  });
24
93
  }
25
94
  /**
26
- * Stops the language server
95
+ * Stops the language server.
96
+ *
97
+ * This method should be called when the LSP server is no longer needed to
98
+ * free up system resources.
99
+ *
27
100
  * @returns {Promise<void>}
101
+ *
102
+ * @example
103
+ * // When done with LSP features
104
+ * await lsp.stop(); // Clean up resources
28
105
  */
29
106
  async stop() {
30
107
  await this.toolboxApi.lspStop(this.instance.id, {
@@ -33,9 +110,19 @@ class LspServer {
33
110
  });
34
111
  }
35
112
  /**
36
- * Notifies the server that a file has been opened
37
- * @param {string} path - Path to the opened file
113
+ * Notifies the language server that a file has been opened.
114
+ *
115
+ * This method should be called when a file is opened in the editor to enable
116
+ * language features like diagnostics and completions for that file. The server
117
+ * will begin tracking the file's contents and providing language features.
118
+ *
119
+ * @param {string} path - Absolute path to the opened file
38
120
  * @returns {Promise<void>}
121
+ *
122
+ * @example
123
+ * // When opening a file for editing
124
+ * await lsp.didOpen('/workspace/project/src/index.ts');
125
+ * // Now can get completions, symbols, etc. for this file
39
126
  */
40
127
  async didOpen(path) {
41
128
  await this.toolboxApi.lspDidOpen(this.instance.id, {
@@ -45,9 +132,17 @@ class LspServer {
45
132
  });
46
133
  }
47
134
  /**
48
- * Notifies the server that a file has been closed
49
- * @param {string} path - Path to the closed file
135
+ * Notifies the language server that a file has been closed.
136
+ *
137
+ * This method should be called when a file is closed in the editor to allow
138
+ * the language server to clean up any resources associated with that file.
139
+ *
140
+ * @param {string} path - Absolute path to the closed file
50
141
  * @returns {Promise<void>}
142
+ *
143
+ * @example
144
+ * // When done editing a file
145
+ * await lsp.didClose('/workspace/project/src/index.ts');
51
146
  */
52
147
  async didClose(path) {
53
148
  await this.toolboxApi.lspDidClose(this.instance.id, {
@@ -57,28 +152,77 @@ class LspServer {
57
152
  });
58
153
  }
59
154
  /**
60
- * Gets document symbols (functions, classes, etc.)
61
- * @param {string} path - Path to the file
62
- * @returns {Promise<LspSymbol[]>} Array of document symbols
155
+ * Get symbol information from a document.
156
+ *
157
+ * This method returns information about all symbols (functions, classes,
158
+ * variables, etc.) defined in the specified document.
159
+ *
160
+ * @param {string} path - Absolute path to the file to get symbols from
161
+ * @returns {Promise<LspSymbol[]>} List of symbols in the document. Each symbol includes:
162
+ * - name: The symbol's name
163
+ * - kind: The symbol's kind (function, class, variable, etc.)
164
+ * - location: The location of the symbol in the file
165
+ *
166
+ * @example
167
+ * // Get all symbols in a file
168
+ * const symbols = await lsp.documentSymbols('/workspace/project/src/index.ts');
169
+ * symbols.forEach(symbol => {
170
+ * console.log(`${symbol.kind} ${symbol.name}: ${symbol.location}`);
171
+ * });
63
172
  */
64
173
  async documentSymbols(path) {
65
174
  const response = await this.toolboxApi.lspDocumentSymbols(this.instance.id, this.languageId, this.pathToProject, 'file://' + path);
66
175
  return response.data;
67
176
  }
68
177
  /**
69
- * Searches for symbols across the workspace
70
- * @param {string} query - Search query
71
- * @returns {Promise<LspSymbol[]>} Array of matching symbols
178
+ * Searches for symbols across the entire Sandbox.
179
+ *
180
+ * This method searches for symbols matching the query string across all files
181
+ * in the Sandbox. It's useful for finding declarations and definitions
182
+ * without knowing which file they're in.
183
+ *
184
+ * @param {string} query - Search query to match against symbol names
185
+ * @returns {Promise<LspSymbol[]>} List of matching symbols from all files. Each symbol includes:
186
+ * - name: The symbol's name
187
+ * - kind: The symbol's kind (function, class, variable, etc.)
188
+ * - location: The location of the symbol in the file
189
+ *
190
+ * @example
191
+ * // Search for all symbols containing "User"
192
+ * const symbols = await lsp.workspaceSymbols('User');
193
+ * symbols.forEach(symbol => {
194
+ * console.log(`${symbol.name} (${symbol.kind}) in ${symbol.location}`);
195
+ * });
72
196
  */
73
197
  async workspaceSymbols(query) {
74
198
  const response = await this.toolboxApi.lspWorkspaceSymbols(this.instance.id, this.languageId, this.pathToProject, query);
75
199
  return response.data;
76
200
  }
77
201
  /**
78
- * Gets code completion suggestions
79
- * @param {string} path - Path to the file
80
- * @param {Position} position - Cursor position
81
- * @returns {Promise<CompletionList>} List of completion suggestions
202
+ * Gets completion suggestions at a position in a file.
203
+ *
204
+ * @param {string} path - Absolute path to the file
205
+ * @param {Position} position - The position in the file where completion was requested
206
+ * @returns {Promise<CompletionList>} List of completion suggestions. The list includes:
207
+ * - isIncomplete: Whether more items might be available
208
+ * - items: List of completion items, each containing:
209
+ * - label: The text to insert
210
+ * - kind: The kind of completion
211
+ * - detail: Additional details about the item
212
+ * - documentation: Documentation for the item
213
+ * - sortText: Text used to sort the item in the list
214
+ * - filterText: Text used to filter the item
215
+ * - insertText: The actual text to insert (if different from label)
216
+ *
217
+ * @example
218
+ * // Get completions at a specific position
219
+ * const completions = await lsp.completions('/workspace/project/src/index.ts', {
220
+ * line: 10,
221
+ * character: 15
222
+ * });
223
+ * completions.items.forEach(item => {
224
+ * console.log(`${item.label} (${item.kind}): ${item.detail}`);
225
+ * });
82
226
  */
83
227
  async completions(path, position) {
84
228
  const response = await this.toolboxApi.lspCompletions(this.instance.id, {