Class TSLanguageServices
- java.lang.Object
-
- ca.cgjennings.apps.arkham.plugins.typescript.TSLanguageServices
-
public final class TSLanguageServices extends java.lang.Object
Provides low-level access to TypeScript language services from Java. Methods of this class delegate to a service provider that runs in another thread. Each method generally comes in two flavours: a synchronous version that blocks until the operation completes, or a version which accepts a callback. When callbacks are used, the callback is always invoked on the event dispatch thread. Synchronous methods can be called from any thread.For most purposes, it is easier and more convenient to use a
CompilationRoot
to access these services.- Author:
- Chris Jennings
-
-
Constructor Summary
Constructors Constructor Description TSLanguageServices()
Creates a new language service.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CompiledSource
compile(java.lang.Object languageService, java.lang.String fileName)
Compiles a source file.void
compile(java.lang.Object languageService, java.lang.String fileName, java.util.function.Consumer<CompiledSource> cb)
Compiles a source file.java.lang.Object
createLanguageService(CompilationRoot root)
Creates a language service instance from the given root.java.lang.Object
createLanguageService(java.lang.Object languageServiceHost)
Creates a language service instance from the given host.java.lang.Object
createLanguageServiceHost(CompilationRoot root)
Creates a language service host from the given root.java.lang.Object
createSnapshot(java.lang.String script)
Creates a script snapshot from the text of a script.static void
debugRestart()
void
dispose()
Releases resources consumed by the services when no longer needed.CompletionInfo.EntryDetails
getCodeCompletionDetails(java.lang.Object languageService, java.lang.String fileName, int position, CompletionInfo.Entry completion)
Returns further details about a code completion returned fromgetCodeCompletions(java.lang.Object, java.lang.String, int)
.CompletionInfo
getCodeCompletions(java.lang.Object languageService, java.lang.String fileName, int position)
Returns a collection of code completions or null.java.util.List<Diagnostic>
getDiagnostics(java.lang.Object languageService, java.lang.String fileName, boolean includeSyntactic, boolean includeSemantic)
Returns a list of diagnostic messages for a file.void
getDiagnostics(java.lang.Object languageService, java.lang.String fileName, boolean includeSyntactic, boolean includeSemantic, java.util.function.Consumer<java.util.List<Diagnostic>> cb)
Returns a list of diagnostic messages for a file.NavigationTree
getNavigationTree(java.lang.Object languageService, java.lang.String fileName)
Returns a file's current navigation tree.void
getNavigationTree(java.lang.Object languageService, java.lang.String fileName, java.util.function.Consumer<NavigationTree> callback)
Returns a file's current navigation tree.Overview
getOverview(java.lang.Object languageService, java.lang.String fileName, int position)
Returns a tool tip of information about the specified position.java.lang.Object
getServicesLib()
Returns the raw TypeScript service library JS object for development and debugging.void
getServicesLib(java.util.function.Consumer<java.lang.Object> cb)
Returns the raw TypeScript service library JS object for development and debugging.static TSLanguageServices
getShared()
Returns the shared default instance.java.lang.String
getVersion()
Gets the services library version as a string.void
getVersion(java.util.function.Consumer<java.lang.String> cb)
Gets the services library version as a string.boolean
isLoaded()
Return whether the services have finished loading and begun accepting commands.java.lang.String
transpile(java.lang.String fileName, java.lang.String script)
Performs a simple transpilation of a single file to JavaScript code.void
transpile(java.lang.String fileName, java.lang.String script, java.util.function.Consumer<java.lang.String> cb)
Performs a simple transpilation of a single file to JavaScript code.
-
-
-
Constructor Detail
-
TSLanguageServices
public TSLanguageServices()
Creates a new language service. The new service will immediately start loading in another thread. Since language service instances are expensive to create and designed to be shared, use the shared instance unless you know what you are doing.
-
-
Method Detail
-
getShared
public static TSLanguageServices getShared()
Returns the shared default instance.- Returns:
- a shared instance
-
isLoaded
public boolean isLoaded()
Return whether the services have finished loading and begun accepting commands.- Returns:
- true if the services have finished initializing
-
dispose
public void dispose()
Releases resources consumed by the services when no longer needed. The result of using this instance after calling this method is undefined.
-
getVersion
public void getVersion(java.util.function.Consumer<java.lang.String> cb)
Gets the services library version as a string.- Parameters:
cb
- the callback that will receive the result
-
getVersion
public java.lang.String getVersion()
Gets the services library version as a string.- Returns:
- the version
-
getServicesLib
public void getServicesLib(java.util.function.Consumer<java.lang.Object> cb)
Returns the raw TypeScript service library JS object for development and debugging.- Parameters:
cb
- the callback that will receive the result
-
getServicesLib
public java.lang.Object getServicesLib()
Returns the raw TypeScript service library JS object for development and debugging.- Returns:
- the TS services library
-
debugRestart
public static void debugRestart()
-
transpile
public void transpile(java.lang.String fileName, java.lang.String script, java.util.function.Consumer<java.lang.String> cb)
Performs a simple transpilation of a single file to JavaScript code. Performs no type checking and reports no errors.- Parameters:
fileName
- an optional fileName for the scriptscript
- the text of the scriptcb
- the callback that will receive the result
-
transpile
public java.lang.String transpile(java.lang.String fileName, java.lang.String script)
Performs a simple transpilation of a single file to JavaScript code. Performs no type checking and reports no errors.- Parameters:
fileName
- an optional fileName for the scriptscript
- the text of the script- Returns:
- the JavaScript equivalent of the specified script text
-
createSnapshot
public java.lang.Object createSnapshot(java.lang.String script)
Creates a script snapshot from the text of a script.- Parameters:
script
- the script to snapshot- Returns:
- the snapshot object
-
createLanguageServiceHost
public java.lang.Object createLanguageServiceHost(CompilationRoot root)
Creates a language service host from the given root.- Parameters:
root
- the compilation root to delegate to- Returns:
- a language service host
-
createLanguageService
public java.lang.Object createLanguageService(CompilationRoot root)
Creates a language service instance from the given root.- Parameters:
root
- the compilation root to delegate to- Returns:
- a language service
-
createLanguageService
public java.lang.Object createLanguageService(java.lang.Object languageServiceHost)
Creates a language service instance from the given host.- Parameters:
languageServiceHost
- the host instance- Returns:
- a language service
-
compile
public void compile(java.lang.Object languageService, java.lang.String fileName, java.util.function.Consumer<CompiledSource> cb)
Compiles a source file.- Parameters:
languageService
- the language servicefileName
- the name of the file to compilecb
- the callback that will receive the result
-
compile
public CompiledSource compile(java.lang.Object languageService, java.lang.String fileName)
Compiles a source file.- Parameters:
languageService
- the language servicefileName
- the name of the file to compile- Returns:
- the compilation output
-
getDiagnostics
public void getDiagnostics(java.lang.Object languageService, java.lang.String fileName, boolean includeSyntactic, boolean includeSemantic, java.util.function.Consumer<java.util.List<Diagnostic>> cb)
Returns a list of diagnostic messages for a file.- Parameters:
languageService
- the language service that manages the filefileName
- the file name to get diagnostics forincludeSyntactic
- if true, includes syntax-related diagnosticsincludeSemantic
- if true, includes semantic diagnostics
-
getDiagnostics
public java.util.List<Diagnostic> getDiagnostics(java.lang.Object languageService, java.lang.String fileName, boolean includeSyntactic, boolean includeSemantic)
Returns a list of diagnostic messages for a file.- Parameters:
languageService
- the language service that manages the filefileName
- the file name to get diagnostics forincludeSyntactic
- if true, includes syntax-related diagnosticsincludeSemantic
- if true, includes semantic diagnostics- Returns:
- a list of diagnostics, or null
-
getCodeCompletions
public CompletionInfo getCodeCompletions(java.lang.Object languageService, java.lang.String fileName, int position)
Returns a collection of code completions or null.- Parameters:
languageService
- the language service that manages the filefileName
- the file name to get diagnostics forposition
- the offset into the source file
-
getCodeCompletionDetails
public CompletionInfo.EntryDetails getCodeCompletionDetails(java.lang.Object languageService, java.lang.String fileName, int position, CompletionInfo.Entry completion)
Returns further details about a code completion returned fromgetCodeCompletions(java.lang.Object, java.lang.String, int)
.- Parameters:
languageService
- the language service that manages the filefileName
- the file name to get diagnostics forposition
- the offset into the source filecompletion
- the completion that details are requested for- Returns:
- the additional details, such as signature and doc comments
-
getNavigationTree
public void getNavigationTree(java.lang.Object languageService, java.lang.String fileName, java.util.function.Consumer<NavigationTree> callback)
Returns a file's current navigation tree.- Parameters:
languageService
- the language service that manages the filefileName
- the file name to get diagnostics for
-
getNavigationTree
public NavigationTree getNavigationTree(java.lang.Object languageService, java.lang.String fileName)
Returns a file's current navigation tree.- Parameters:
languageService
- the language service that manages the filefileName
- the file name to get diagnostics for- Returns:
- the file's current navigation tree
-
getOverview
public Overview getOverview(java.lang.Object languageService, java.lang.String fileName, int position)
Returns a tool tip of information about the specified position.- Parameters:
languageService
- the language service that manages the filefileName
- the file name to get diagnostics forposition
- the offset into the source file
-
-