fidl-lsp
is an LSP Language Server for FIDL.
See the VSCode extension README for more information on how to install and setup the FIDL LSP extension in VSCode.
To launch a local test instance of VSCode running the extension:
fx gen
and then fx build build/fidl:validate_fidl_project_json
to make sure fidl_project.json exists.fidl-lint
: fx build host_x64/fidl-lint
.build-vscode.sh
.fidl-misc/vscode-language-fidl/
directory in VSCode, and run the Launch Extension
task.To run tests: go test -p 1 ./...
The -p
flag specifies that we don't want tests run in parallel, as some of them write to and read from the filesystem and can collide. If you want to force your tests to be re-run (as test results are cached and not re-run until code in that package has changed), you can run with the flag -count 1
.
The general flow of control in the language server goes like this:
langserver/handler.go
LangHandler
tells the FileSystem
to make the changeLangHandler
triggers a re-analysis by the Analyzer
LangHandler
dispatches the request to the Analyzer
Analyzer
extracts the needed information and returns itLangHandler
sends the response to the clientlangserver
packageThis package includes the core logic of the language server. It deals with LSP specific boilerplate, JSON-RPC messages, etc. It includes the LangHandler
type, which handles LSP requests, sends reponses and notifications to the client, and dispatches changes to the state manager or requests for analyses to the Analyzer
.
state
packageThe language server's state management is in the state
package. Currently this is just an in memory file system (mapping of editor file names to file text). This could be wrapped in e.g. an RWLock
to enable concurrent handling of LSP requests and notifications.
analysis
packageThe “backend” of the server, which doesn't know about LSP but knows how to compile FIDL and analyze the JSON IR.
Includes the Analyzer
type, which maintains a set of compiled FIDL Library
s and their constituent files, dependencies, and build artifacts. Main entry point is Analyzer.Analyze()
, which is called every time a file is changed on the client. Analyze
recompiles the relevant FIDL library for that file and imports the JSON IR.
The Analyzer
compiles FIDL libraries by invoking fidlc
in a separate process, gets diagnostics from fidlc
and fidl-lint
, and uses fidl-format
for formatting. It locates dependencies using a fidl_project.json
file, the path to which will be configurable in the LSP client extension. fidl_project.json
declares all FIDL libraries the language server should be aware of, the paths to their constituent files, the path to their JSON IR, and their dependencies (by library name).
This list documents LSP features supported by fidl-lsp.