Documentation
¶
Overview ¶
Package typescript is the TypeScript language pack (SPEC §8.1, §10.15, §10.34): TypeScript and TypeScript React. The grammars and language configurations are in assets/, copied by scripts/update-assets.sh; the licenses are in third_party/ and NOTICE. Since step 24b.5 the pack also runs typescript-language-server for TypeScript and for the JavaScript pack's languages (JavaScript and JavaScript React): the server is found, started and shown by extensions/internal/langserver (the path setting typescript.languageServer.path, PATH, the status item, the notification for a missing server), node runs it (typescript.nodePath), the preferences of VS Code's typescript.* and javascript.* settings are sent to it, and the pack owns the choice of the TypeScript it uses: the one beside the server or the folder's own, offered once and never taken (version.go), with "TypeScript: Select TypeScript Version..." and the version in the status item. The commands are VS Code's: Restart TS Server, Go to Project Configuration, Go to Source Definition, Find All File References, Organize Imports, Sort Imports and Remove Unused Imports. Since step 25.10 the pack also adds to the debugger of the JavaScript pack what a TypeScript program needs (debug.go).
Index ¶
Constants ¶
const ( // RestartCommand restarts the language server ("TypeScript: Restart TS Server"). RestartCommand = "typescript.restartTsServer" // SelectVersionCommand lists the TypeScript versions and keeps the choice for the folder ("TypeScript: Select TypeScript Version..."). // A string argument is the choice (ChoiceGlobal or ChoiceWorkspace) to make without asking. SelectVersionCommand = "typescript.selectTypeScriptVersion" // GoToProjectConfigCommand and GoToJSProjectConfigCommand open the tsconfig.json or jsconfig.json of the file in front. GoToProjectConfigCommand = "typescript.goToProjectConfig" GoToJSProjectConfigCommand = "javascript.goToProjectConfig" // GoToSourceDefinitionCommand goes to the definition in the source of a library instead of its declaration file. GoToSourceDefinitionCommand = "typescript.goToSourceDefinition" // FindFileReferencesCommand lists the places that import the file in front (or the file the command is given). FindFileReferencesCommand = "typescript.findAllFileReferences" // OrganizeImportsCommand sorts and combines the imports of the file in front and removes the unused ones. OrganizeImportsCommand = "typescript.organizeImports" // SortImportsCommand and RemoveUnusedImportsCommand do one half of it; the JavaScript variants are the same for the JavaScript files. SortImportsCommand = "typescript.sortImports" JSSortImportsCommand = "javascript.sortImports" RemoveUnusedImportsCommand = "typescript.removeUnusedImports" JSRemoveUnusedImportsCommand = "javascript.removeUnusedImports" )
The ids of the commands.
const ( RequirementNode = "node" RequirementTypeScript = "typescript-package" )
The ids of the requirements of the extension besides the server's.
const ( // ID is the id of the extension, and ServerID the id of its language server in the manifest. ID = "emetos.typescript" ServerID = "typescript" // PathSetting holds the path of the typescript-language-server program. PathSetting = "typescript.languageServer.path" // StateKey is the key of the state under which the TypeScript the user chose for the folder is kept (ChoiceGlobal or ChoiceWorkspace). StateKey = "typescript.version" )
The ids the pack uses.
const ( // NodePathSetting is the node program that runs typescript-language-server, when it is not the first on PATH. NodePathSetting = "typescript.nodePath" // TsdkSetting is the lib folder of the TypeScript the server uses when the user has not chosen the folder's own. TsdkSetting = "typescript.tsdk" // PromptWorkspaceVersionSetting says whether the folder's own TypeScript is offered once (VS Code's name). PromptWorkspaceVersionSetting = "typescript.enablePromptUseWorkspaceTsdk" // NpmPathSetting is the npm program tsserver fetches the types of libraries with. NpmPathSetting = "typescript.npm" // LocaleSetting is the language of tsserver's messages. LocaleSetting = "typescript.locale" // DisableTypeAcquisitionSetting stops tsserver from fetching the @types packages of the imports it cannot resolve. DisableTypeAcquisitionSetting = "typescript.disableAutomaticTypeAcquisition" // MaxMemorySetting is the memory tsserver may use, in megabytes. MaxMemorySetting = "typescript.tsserver.maxTsServerMemory" // TraceSetting traces the traffic with the server (the host's). TraceSetting = "typescript.trace.server" )
The settings that are not options: the program, node, the TypeScript and the server's resources.
const ( // SourceGlobal is the TypeScript installed beside the language server (the one `npm install -g typescript` puts there). SourceGlobal = "global" // SourceTsdk is the folder typescript.tsdk names. SourceTsdk = "typescript.tsdk" // SourceWorkspace is the node_modules/typescript of the folder (or of a folder above it). SourceWorkspace = "workspace" )
The sources of a Version.
const ( // ChoiceGlobal uses the TypeScript beside the server (or typescript.tsdk); ChoiceWorkspace the folder's own. ChoiceGlobal = "global" ChoiceWorkspace = "workspace" )
The choices kept in the state under StateKey.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Plan ¶
type Plan struct {
// Use is the version the server is told to use.
Use Version
// Global is the version of the user's own installation (typescript.tsdk, else beside the server) when there is one, and Workspace
// the folder's own when it has one.
Global, Workspace *Version
}
Plan is the TypeScript decision of one start of the server.
func Decide ¶
func Decide(env langserver.Env, server, root, tsdk, chosen string) (Plan, error)
Decide chooses the TypeScript for a start. chosen is what the user chose for the folder (ChoiceGlobal, ChoiceWorkspace or ""), tsdk the value of typescript.tsdk and server the path of the language server's file. The folder's own TypeScript is used only when chosen says so (and it is there); otherwise the global one, which fails with TypeScriptNotFound when there is none, and the message says that the folder has its own, if it does. It fails with TypeScriptTsdkInvalid for a typescript.tsdk that is wrong.
type Version ¶
type Version struct {
// Source is where it was found: SourceGlobal, SourceTsdk or SourceWorkspace.
Source string
// Lib is the folder that holds tsserver.js (.../node_modules/typescript/lib) and Number the version its package.json tells
// ("5.9.3"; empty when it cannot be read).
Lib, Number string
}
Version is a TypeScript package that has a tsserver.js.
func BesideServer ¶
BesideServer is the TypeScript node would find from the language server's own file: the node_modules/typescript of the folders above the real file of the server (the link in a bin folder is followed), as require.resolve('typescript') looks for it. It reads files and runs nothing.
func TsdkVersion ¶
func TsdkVersion(env langserver.Env, value string) (Version, error)
TsdkVersion resolves typescript.tsdk, which names the lib folder, the package folder or the tsserver.js itself. It fails with TypeScriptTsdkInvalid when the value is none of them.
func WorkspaceVersion ¶
WorkspaceVersion is the TypeScript of the node_modules of the folder root or of the nearest folder above it that has one, climbing as ResolveRoot does: not past the top of a repository (the folder with .git), the home folder or the root of the file system, and twelve folders at most. It reads files and runs nothing.