arduino / arduino-language-server

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

[question] Can arduino-language-server use arduino-lint to provide diagnostic for arduino language? #164

Closed Freed-Wu closed 1 year ago

Freed-Wu commented 1 year ago

Does arduino-language-server use arduino-lint to provide diagnostic for arduino language?

per1234 commented 1 year ago

Hi @Freed-Wu. Arduino Language Server does not use Arduino Lint in any way. Arduino Lint wouldn't actually have much to offer to the language server because there is actually only one rule related to sketch code (SC001).

General linting of Arduino code was considered out of scope for Arduino Lint because the Arduino language is essentially C++ and there are already excellent tools available for linting C++ code.

Arduino Language Server acts as a translator between the Arduino sketch build system and the clangd C++ language server. Arduino Language Server handles the process of running Clangd on the C++ code generated from the sketch code by the build system in Arduino CLI and then translating the Clangd results to be relevant for the source Arduino sketch code. In this way, this existing excellent C++ language server is leveraged for the benefit of Arduino users rather than Arduino having to create something from scratch.

If you are interested in diagnostics for other types of Arduino project files, many of Arduino Lint's rules are based on JSON schema. In theory, it should be possible to incorporate the schemas into a high quality programming editor such as VS Code to enhance the process of editing those project files:

https://github.com/arduino/arduino-lint/tree/main/etc/schemas

Since the package index files use the standard JSON data format, I think the package index schema should be relatively easy to use. Unfortunately I think the other schemas will be more challenging though. The reason is that the library.properties, boards.txt, boards.local.txt, platform.txt, platform.local.txt, and programmers.txt files are in a bespoke "properties" data format. So you would need to parse them into a standard data structure that can be read by the JSON schema validator. Arduino does provide a Go module for working with the "properties" data format:

https://github.com/arduino/go-properties-orderedmap

Freed-Wu commented 1 year ago

rather than Arduino having to create something from scratch.

I know: arduino-language-server use clangd to diagnostic which is better than arduino-lint from scratch.

If you are interested in diagnostics for other types of Arduino project files

Why it doesn't push https://github.com/arduino/arduino-lint/tree/main/etc/schemas to https://www.schemastore.org/json/? I use coc.nvim which has many extensions diagnostic json, yaml, toml, ... by json schema from https://www.schemastore.org/json/.

per1234 commented 1 year ago

Why it doesn't push https://github.com/arduino/arduino-lint/tree/main/etc/schemas to https://www.schemastore.org/json/?

Thanks for the suggestion. This idea is actually something we had in the internal issue tracker for the last couple years. I have now published it to the public issue tracker: https://github.com/arduino/arduino-lint/issues/567

As I mentioned above, I am skeptical about whether anyone would be able to use the schemas for the "properties" data format files, but it would be worth at least considering publishing the Arduino package index schema.