Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"goto" features don't work for files in sketch src folder #722

Open
per1234 opened this issue Dec 27, 2021 · 3 comments
Open

"goto" features don't work for files in sketch src folder #722

per1234 opened this issue Dec 27, 2021 · 3 comments
Assignees
Labels
topic: language server Related to the Arduino Language Server type: imperfection Perceived defect in any part of project

Comments

@per1234
Copy link
Contributor

per1234 commented Dec 27, 2021

Describe the problem

Arduino sketches may contain additional code files under the src subfolder. This folder is included in the build and source files it contains are recursively compiled.

The Arduino IDE's language server-based features include "Go to definition" and "Peek", which reveal the definition of a code component. This works even for definitions in files not currently open in the IDE, such as libraries.

🐛 The "goto" features do not work for code components from files under the src subfolder of the sketch.

To reproduce

  1. Download and open this sketch in Arduino IDE:
    HasSrc.zip
  2. Select Tools > Board > Arduino AVR Boards > Arduino Uno from the Arduino IDE menus.
  3. Right click on foo.h in this line:
    #include "src/foo.h"
  4. Select "Go to Definition" from the context menu.
    🐛 The src/foo.h file does not open in an editor tab.
  5. Right click on foo.h again.
  6. Select "Peek" from the context menu.
  7. Select "Peek Definition" from the submenu.
    🐛 The src/foo.h file does not open in an editor peek.

Expected behavior

The same behavior from the "goto" features when used on code components from the src subfolder of the sketch as from files from any other location.

Arduino IDE version

Original report

2.0.0-rc3

Last verified with

9a6a457

Operating system

Windows

Operating system version

11

Additional context

Language server logs: HasSrc-logs.zip

I notice that the "goto" attempts trigger the creation of a new Arduino Language Server temporary folder, which breaks the URIs I see for src/foo.h in the language server logs (e.g., file:///C:/Users/per/AppData/Local/Temp/arduino-language-server410042786/sketch/src/foo.h).

@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: language server Related to the Arduino Language Server labels Dec 27, 2021
@per1234
Copy link
Contributor Author

per1234 commented Mar 11, 2022

There is additional discussion, which gets into speculation about the cause of the problem at #323

@mink99
Copy link

mink99 commented Mar 17, 2022

I added another simple example :
src :

#include "inc.h"
void setup() {
  Serial.begin(9600);
}
void loop() {}

included : inc.h

void doit() {
  Serial.println("epic fail");
}

result :
Serial is known in the main , but is a clang error in "inc.h"

Image7

@per1234
Copy link
Contributor Author

per1234 commented Mar 17, 2022

I don't think that is the same problem @mink99.

The Arduino sketch precompiler automatically adds an #include directive to the sketch_mar17a.ino. That provides the declaration of Serial. But that is only done for .ino files. There is no sketch preprocessing for .h files, so Serial is indeed undeclared in that code.

You will get the same even if you run clangd directly on the equivalent C++ program.

If you want to use the Arduino API in the sketch code files that don't have a .ino file extension, you should add the #include directive to them:

#include <Arduino.h>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: language server Related to the Arduino Language Server type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

3 participants