arduino / arduino-language-server

An Arduino Language Server based on Clangd to Arduino code autocompletion
GNU Affero General Public License v3.0
120 stars 11 forks source link

Some tweaks on how sketch is rebuild during editing #118

Closed cmaglie closed 2 years ago

cmaglie commented 2 years ago

Please check if the PR fulfills these requirements

What kind of change does this PR introduce? With this patch, we should gain some speed improvements in sketch rebuilds by caching libraries detection results from previous builds.

What is the current behavior? When the sketch is rebuilt the libraries detection phase could take a very long time, especially if the sketch uses a lot of libraries or even a single library that contains a lot of files.

What is the new behavior? The sketch is now rebuilt skipping the libraries detection and using the libraries detected on the latest "full" build. A single "full" build is done when the language server is started, all subsequent builds will be without libraries detection. This means that #include <...> added after the language server startup may not be indexed/recognized until the next full build.

To trigger a new "full" build there are now two ways:

  1. restart the language server
  2. send a arduino/buildCompleted LSP notification from the IDE

The arduino/buildCompleted notification is an Arduino custom notification (it's not part of the LSP specification), it should be sent by the IDE to the language server after a full compile is triggered by the user of the IDE. Inside the notification, there is a buildPath field that should point to the path of the build directory so the language server can pick the result of libraries detection from there.

Other information This PR uses a patched arduino-cli that support the SkipLibrariesDiscovery flag: https://github.com/arduino/arduino-cli/pull/1777

kittaakos commented 2 years ago

We should look into Language Server Index Format Specification (LSIF):

The purpose of the Language Server Index Format (LSIF) is it to define a standard format for language servers or other programming tools to dump their knowledge about a workspace. This dump can later be used to answer language server LSP requests for the same workspace without running the language server itself.

kittaakos commented 2 years ago

It looks promising.

In inols.log:

{"jsonrpc":"2.0","method":"arduino/buildCompleted","params":{"build_path":"/private/var/folders/z1/xkw1yh5n7rz4n8djprp1mdn80000gn/T/arduino-sketch-2A25CBEDDFEB3508AE8DDDA45D126AAA"}}Content-Length: 58

In inols-err.log: (I do not know if it's promising but it's there)

15:15:04.433519 IDE --> LS NOTIF arduino/buildCompleted
15:15:04.433562                  arduino/buildCompleted: write-locked
15:15:04.475205                  arduino/buildCompleted: write-unlocked
cmaglie commented 2 years ago

I've included most of your changes here. We should probably document better the ino/didCompleteBuild custom command.