Syntax Reference
LanguageServer.LanguageServerInstanceLanguageServer.RangeLanguageServer.get_line_offsetsLanguageServer.get_offsetLanguageServer.get_position_from_offsetLanguageServer.index_atLanguageServer.is_completion_matchLanguageServer.is_diag_dependent_on_envLanguageServer.runserver
Main
LanguageServer.Range — MethodRange(Doc, rng)Converts a byte offset range to a LSP Range.
LanguageServer.get_line_offsets — Methodget_line_offsets(doc::Document)Updates the doc.lineoffsets field, an n length Array each entry of which gives the byte offset position of the start of each line. This always starts with 0 for the first line (even if empty).
LanguageServer.get_offset — Methodget_offset(doc, line, char)Returns the 0 based byte offset position corresponding to a line/character position. This takes 0 based line/char inputs. Corresponding functions are available for Position and Range arguments, the latter returning a UnitRange{Int}.
LanguageServer.get_position_from_offset — Methodget_position_from_offset(doc, offset)Returns the 0-based line and character position within a document of a given byte offset.
LanguageServer.index_at — Functionindex_at(doc::TextDocument, p::Position, forgiving_mode=false)Converts a 0-based Position that is UTF-16 encoded to a 1-based UTF-8 encoded Julia string index.
LanguageServer.is_diag_dependent_on_env — Methodisdiagdependentonenv(diag::Diagnostic)::Bool
Is this diagnostic reliant on the current environment being accurately represented?
LanguageServer.LanguageServerInstance — TypeLanguageServerInstance(pipe_in, pipe_out, env="", depot="", err_handler=nothing, symserver_store_path=nothing)Construct an instance of the language server.
Once the instance is run, it will read JSON-RPC from pipe_out and write JSON-RPC from pipe_in according to the language server specification. For normal usage, the language server can be instantiated with LanguageServerInstance(stdin, stdout, false, "/path/to/environment").
Arguments
pipe_in::IO: Pipe to read JSON-RPC from.pipe_out::IO: Pipe to write JSON-RPC to.env::String: Path to the environment for which the language server is running. An empty string uses julia's default environment.depot::String: Sets theJULIA_DEPOT_PATHwhere the language server looks for packages required inenv.err_handler::Union{Nothing,Function}: If notnothing, catch all errors and pass them to an error handler function with signatureerr_handler(err, bt). Mostly used for the VS Code crash reporting implementation.symserver_store_path::Union{Nothing,String}: ifnothingis passed, the symbol server cash is stored in a folder in the package. If an absolute path is passed, the symbol server will store the cache files in that path. The path must exist on disc before this is called.
Base.run — Methodrun(server::LanguageServerInstance)Run the language server.
LanguageServer.runserver — Functionrunserver(pipe_in=stdin, pipe_out=stdout[, env_path])Run a LanguageServerInstance reading from pipe_in and writing to pipe_out.
The same options can be passed to runserver as to LanguageServerInstance. If env_path is not specified, attempt to pick an environment by considering in order of priority:
ARGS[1]: the first command-line argument passed to the invocation ofjulia.- The Julia project containing
pwd(). - The default Julia environment withing
.julia/environments/v#.#.
Examples
The following invocation of Julia would set env_path to /home/example/repos/Example.jl:
julia --project=/path/to/LanguageServer.jl \
-e "using LanguageServer; runserver()" \
/home/example/repos/Example.jlIf there was a Project.toml or JuliaProject.toml in /home/example/repos/Example.jl/, the following invocation would set env_path to /home/example/repos/Example.jl/; otherwise it would be set to .julia/environments/v#.# where v#.# is the major/minor version of Julia being invoked.
julia --project=/path/to/LanguageServer.jl \
-e "using LanguageServer; runserver()"Requests
LanguageServer.is_completion_match — Functionis_completion_match(s::AbstractString, prefix::AbstractString, cutoff=3)Returns true if s starts with prefix or has a sufficiently high fuzzy score.