[lsp] Initial commit of FIDL LSP Language Server

This CL includes the basic infrastructure for the FIDL Language Server,
including the server's handling of LSP requests over JSON-RPC, file
synchronization with the client, dependency management and FIDL library
compilation, and two language features: diagnostics (errors/warnings/
lints) and formatting.

The general flow of control in the language server goes like this:
- A request/notification is received in langserver/handler.go
- If it is a notification (changing state of the open files):
    - The LangHandler tells the FileSystem to make the change
    - The LangHandler triggers a re-analysis by the Analyzer
- If it is a request for some language feature:
    - The LangHandler dispatches the request to the Analyzer
    - The Analyzer extracts the needed information and returns it
    - The LangHandler sends the response to the client

The core logic of the language server is in the `langserver` package.
This package deals with LSP specific boilerplate, JSON-RPC messages,
etc.
  handler.go:     defines the LangHandler, which takes LSP requests and
                  sends reponses and notifications to the client, and
                  dispatches changes or requests for analyses.
  files.go:       LangHandler methods that dispatch requests to the
                  FileSystem.
  format.go:      LangHandler method that handles formatting request
  diagnostics.go: LangHandler.publishDiagnostics

The 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.
  fs.go:          defines the FileSystem, which keeps the server's VFS
                  in sync with the client's edits.
  parse.go:       functions that use regex to find `library` and
                  `using` declarations in in-memory FIDL files.

The "backend" of the server, which doesn't know about LSP but knows how
to compile FIDL and analyze the JSON IR, is in the `analysis` package.
  analyzer.go:    definition of Analyzer, the Library type, and the
                  Analyze method, which is called every time a file
                  is changed on the client. Analyze recompiles the
                  relevant FIDL library and reads in the JSON IR.
  compile.go:     used to compile FIDL libraries to get diagnostics.
  deps.go:        contains FindDeps, which is used to generate a fidlc
                  invocation for a given file.
  library.go:     a representation of a deserialized JSON IR. will be
                  used for future language features.
  format.go:      contains FormatFile, which invokes fidl-format on the
                  specified file.
  diagnostics.go: methods to extract diagnostics from fidlc and
                  fidl-lint output.

gen_fidl_project.py is a script to generate a fidl_project.json file,
which 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).

Test: go test ./...
Change-Id: I24536fd5ed1feb0cc16e0d49077959896494a270
Reviewed-on: https://fuchsia-review.googlesource.com/c/fidl-misc/+/392713
Reviewed-by: Pascal Perez <pascallouis@google.com>
Reviewed-by: Benjamin Prosnitz <bprosnitz@google.com>
22 files changed
tree: 2b293c91928915b63bb8dfdbda21e7105c551512
  1. fidl-lsp/
  2. fidldev/
  3. .gitignore
  4. AUTHORS
  5. CONTRIBUTING.md
  6. LICENSE
  7. PATENTS
  8. README.md
README.md

Fuchsia Open Source Template Repository

This repository is a template that we will use when creating new open source repositories for Fuchsia.