-
Notifications
You must be signed in to change notification settings - Fork 1
server API
Creates a new instance of TypeScript Server.
Returns Object An object containing methods to interact with TypeScript Server.
Initializes the TypeScript Server instance.
This function starts a new process for the TypeScript Server using Node's child_process.spawn.
It sets up listeners for the 'stdout' and 'stderr' streams of the TypeScript Server process,
handling incoming data and errors respectively. It also handles the 'close' event of the process.
The function configures a timeout to reject the promise if the server does not start within a specified time.
-
nodestring The path to the Node.js executable. If not provided, defaults to 'node'. (optional, default"") -
tsServerstring The path to the TypeScript Server executable. If not provided, defaults to the 'tsserver' path in the 'node_modules' directory. (optional, default"")
Returns Promise<void> A promise that resolves when the TypeScript Server is ready, or rejects if there is an error or timeout.
Handles incoming data from the TypeScript Server.
-
rawDatastring Raw data received from tsserver.
Processes a complete message from tsserver.
-
messagestring A complete message in JSON format.
Checks if the buffer has a complete message based on Content-Length.
Returns boolean True if a complete message is present in the buffer.
Sends a command to the TypeScript Server. Special handling for 'open' command as it does not receive a response.
-
commandObject The command object to send. -
timeoutnumber The timeout in milliseconds for the command. (optional, default5000)
Returns Promise<Object> A promise that resolves with the response from tsserver.
Sends an 'open file' command to the TypeScript Server.
-
filePathstring The path to the TypeScript file to open. -
timeoutnumber The timeout in milliseconds for the command. (optional, default5000)
Returns Promise<Object> A promise that resolves with the response from tsserver.
Sends a 'change' command to the TypeScript Server.
-
filePathstring The path to the file. -
startObject The start position of the change (line and offset). -
endObject The end position of the change (line and offset). -
newTextstring The new text to replace in the range.
Sends a 'close' command to the TypeScript Server.
-
filePathstring The path to the file being closed.
Sends a 'definition' request to the TypeScript Server.
-
filePathstring The path to the file. -
linenumber The line number of the position. -
offsetnumber The offset in the line of the position.
Returns Promise<Object> A promise that resolves with the response from tsserver.
Sends a 'quickinfo' request to the TypeScript Server.
-
filePathstring The path to the file. -
linenumber The line number of the position. -
offsetnumber The offset in the line of the position.
Returns Promise<Object> A promise that resolves with the response from tsserver.
Sends a 'references' request to the TypeScript Server.
-
filePathstring The path to the file. -
linenumber The line number of the position. -
offsetnumber The offset in the line of the position.
Returns Promise<Object> A promise that resolves with the response from tsserver.
Sends a 'FindSourceDefinition' request to the TypeScript Server.
-
filePathstring The path to the file. -
linenumber The line number of the position. -
offsetnumber The offset in the line of the position.
Returns Promise<Object> A promise that resolves with the response from tsserver.
Sends a 'completionInfo' command to the TypeScript Server.
-
filePathstring The path to the file. -
linenumber The line number of the position. -
offsetnumber The offset in the line of the position.
Returns Promise<Object> A promise that resolves with the response from tsserver.
Sends a 'completionEntryDetails' request to the TypeScript Server.
-
filePathstring The path to the file. -
linenumber The line number of the position. -
offsetnumber The offset in the line of the position. -
entryNamestring The name of the completion entry.
Returns Promise<Object> A promise that resolves with the response from tsserver.
Sends a 'compileOnSaveAffectedFileList' request to the TypeScript Server.
-
filePathstring The path to the file.
Returns Promise<Object> A promise that resolves with the response from tsserver.
Sends a 'compileOnSaveEmitFile' command to the TypeScript Server.
-
filePathstring The path to the TypeScript file. -
forcedboolean Force emit even if there are errors. (optional, defaultfalse) -
includeLinePositionboolean Include line position in the response. (optional, defaultfalse) -
richResponseboolean If true, returns response as an object with detailed emit results. (optional, defaultfalse)
Returns Promise<(boolean | EmitResult)> A promise that resolves with a boolean indicating success
or an EmitResult object containing detailed information about the emit process.
- If a boolean: true if the emit was successful, false otherwise.
- If an EmitResult object:
- emitSkipped: A boolean indicating whether the emit was skipped.
- diagnostics: An array of Diagnostic or DiagnosticWithLinePosition objects, providing
detailed information about each diagnostic message.
- Diagnostic: An object representing a diagnostic message, typically containing:
- start: The starting position of the diagnostic message.
- length: The length of the diagnostic message.
- text: The text of the diagnostic message.
- DiagnosticWithLinePosition: An extended version of Diagnostic, including line and
character position information:
- start: The starting position of the diagnostic message (line and character).
- end: The ending position of the diagnostic message (line and character).
- text: The text of the diagnostic message.
Sends a 'definitionAndBoundSpan' request to the TypeScript Server.
-
filePathstring The path to the file. -
linenumber The line number of the position. -
offsetnumber The offset in the line of the position.
Returns Promise<Object> A promise that resolves with the response from tsserver.
Sends an 'implementation' request to the TypeScript Server.
-
filePathstring The path to the file. -
linenumber The line number of the position. -
offsetnumber The offset in the line of the position.
Returns Promise<Object> A promise that resolves with the response from tsserver.
Sends a 'format' request to the TypeScript Server.
-
filePathstring The path to the file. -
startLinenumber The starting line number of the format range. -
startOffsetnumber The starting offset in the start line. -
endLinenumber The ending line number of the format range. -
endOffsetnumber The ending offset in the end line. -
formatOptionsobject? Optional formatting options. (optional, default{})
Returns Promise<Object> A promise that resolves with the response from tsserver.
Sends an 'exit' command to the TypeScript Server to gracefully shut it down.
Sends a 'formatonkey' request to the TypeScript Server. This command is used for formatting code at a specific position in a file, typically in response to a keystroke. It's commonly used for auto-formatting a line of code when a specific key (like a closing brace or semi-colon) is pressed.
-
filePathstring The path to the TypeScript file. The path should be absolute or relative to the TypeScript server's current working directory. -
linenumber The 1-based line number in the file where the key was pressed. This and the offset together point to the specific position in the file. -
offsetnumber The 1-based character offset in the line where the key was pressed. This is typically the position right after where the key was pressed. -
keystring The character corresponding to the key pressed. This is typically a single character like ';' or '}' that triggers the formatting action. -
formatOptionsobject? Optional formatting options to customize the formatting behavior. These options might include settings like tab size, indent size, whether to insert spaces, and so on. Example: { tabSize: 4, indentSize: 4, insertSpace: true } (optional, default{})
Returns Promise<Object> A promise that resolves with the response from tsserver. The response typically includes an array of code edits that should be applied to the file to achieve the desired formatting. Each edit suggests changes like text insertions, deletions, or replacements.
- See: exitServer - Sends an 'exit' command to the TypeScript Server for a graceful shutdown.
Terminates the TypeScript Server process. Warning: Use this function with caution. Prefer using the exitServer function for a graceful shutdown.