Skip to content

Commit 16e861d

Browse files
elektronikworkshopadiazulay
authored andcommitted
Added IntelliSense compiler parsing engine code
* Added IntelliSense compiler parsing engine code * First injection of the compiler command parser and IntelliSense auto-configuration. Currently injected into "verify" only. * Updated branch documentation to reflect the current state of this project
1 parent 82513e4 commit 16e861d

File tree

4 files changed

+416
-16
lines changed

4 files changed

+416
-16
lines changed

BRANCHNOTES.md

+24-12
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,31 @@ src/arduino/arduino.ts
2525

2626
### Status
2727
**2020-02-05** Currently I'm able to generate error free IntelliSense setups for AVR and ESP32 using the preliminary implementation. For ESP32 I just had to add the intrinsic compiler paths manually. A solution has to be found for these ... which there is, see [here](https://stackoverflow.com/a/6666338)
28+
**2020-02-06** Got it fully working (with built-in include directories) for AVR, ESP32, ESP8266. Rewrote the backend to facilitate writing of further parser engines in the future.
2829

2930
| | Tasks |
3031
|-----:|:--------|
31-
| **Build output parser** | :heavy_check_mark: Basic parser working* |
32-
| | :white_check_mark: Support for different boards |
32+
| **Build output parser** | :heavy_check_mark: Basic parser working |
33+
| | :heavy_check_mark: Support for different boards (done for AVR, ESP32, ESP8266) -- The code has been designed such that it is easy to write/add new parser engines (for non gcc compilers for instance) |
34+
| | :heavy_check_mark: Getting intrinsic gcc include paths |
35+
| | :heavy_check_mark: Handling quoted arguments |
3336
| | :white_check_mark: X-platform support |
34-
| **`c_cpp_properties.json` generator** | :heavy_check_mark: Basic objects* |
35-
| | :heavy_check_mark: Basic setting of parsing result* |
36-
| | :heavy_check_mark: Basic file input* |
37-
| | :heavy_check_mark: Basic file output* |
37+
| **`c_cpp_properties.json` generator** | :heavy_check_mark: Basic objects |
38+
| | :heavy_check_mark: Basic setting of parsing result |
39+
| | :heavy_check_mark: Basic file input |
40+
| | :heavy_check_mark: Basic file output |
3841
| | :white_check_mark: Merging of parsing result and existing file content |
39-
| | :white_check_mark: Getting intrinsic gcc include paths (partly done)|
42+
| | :white_check_mark: Handling inexistent files and folders |
4043
| **Configuration flags** | :white_check_mark: |
41-
| **Unit tests** | :white_check_mark: Basic parser |
44+
| **Unit tests** | :white_check_mark: Basic parser (known boards, match/no match)|
45+
| | :white_check_mark: Querying of compiler built-in includes |
46+
| | :white_check_mark: Throwing arbitrary data at parser engines |
4247
| | :white_check_mark: JSON input |
4348
| | :white_check_mark: JSON output |
4449
| | :white_check_mark: Configuration merging |
4550
| **General** | :white_check_mark: Review and remove previous attempts messing with `c_cpp_properties.json` |
46-
* not committed to branch yet
51+
52+
`*` not committed to branch yet
4753

4854
## Motivation
4955
I write a lot of code for Arduino, especially libraries. The Arduino IDE is not suited for more complex projects and I tried several alternatives. The old and dysfunctional Arduino CDT extension for eclipse somehow stalled (even if it was promising), Sloeber could be an option but the maintainer is disillusioned and the project is more or less dead. Platform IO IDE's license is very [restrictive](https://community.platformio.org/t/what-part-of-platformio-is-open-source-licenced/1447/2).
@@ -63,6 +69,7 @@ I will list every supporter here, thanks!
6369
1h coding -> 20$ -> 4 :beers:
6470
2020-02-04 Elektronik Workshop: 32 :beers: (8h coding)
6571
2020-02-05 Elektronik Workshop: 40 :beers: (10h coding)
72+
2020-02-06 Elektronik Workshop: 36 :beers: (9h coding)
6673

6774
<!-- https://github.com/StylishThemes/GitHub-Dark/wiki/Emoji -->
6875

@@ -83,7 +90,7 @@ I will list every supporter here, thanks!
8390

8491
## Implementation
8592

86-
### `c_cpp_properties.json` Generator
93+
### Build Output Parser
8794
#### Intrinsic Include Paths
8895
Some include paths are built into gcc and don't have to be specified on the command line. This requires that we have to get them from the compiler.
8996

@@ -96,9 +103,9 @@ won't do since not all include directories are named `include`. Fortunately gcc
96103
# generally for C++
97104
gcc -xc++ -E -v -
98105
# for esp32
99-
~/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/1.22.0-80-g6c4433a-5.2.0/bin/xtensa-esp32-elf-gcc -xc++ -E -v - < /dev/null 2>&1 | tee xtensa-esp32-elf-gcc_built_in_specs.txt
106+
~/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/1.22.0-80-g6c4433a-5.2.0/bin/xtensa-esp32-elf-gcc -xc++ -E -v - < /dev/null > xtensa-esp32-elf-gcc_built_in_specs.txt 2>&1
100107
# avr
101-
~/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/bin/avr-gcc -xc++ -E -v - < /dev/null 2>&1 | tee avr-gcc_built_in_specs.txt
108+
~/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino5/bin/avr-gcc -xc++ -E -v - < /dev/null > avr-gcc_built_in_specs.txt 2>&1
102109
```
103110
The result can be inspected here:
104111
* [xtensa-esp32-elf-gcc_built_in_specs.txt](doc/intellisense/compilerinfo/xtensa-esp32-elf-gcc_built_in_specs.txt)
@@ -127,6 +134,9 @@ End of search list.
127134
```
128135
As one can see with the ESP32-gcc not all include directories are named `include`. Parsing of this output is pretty trivial though.
129136

137+
### `c_cpp_properties.json` Generator
138+
139+
130140
### Settings
131141
Global user settings, on linux under `~/.config/Code/User/settings.json`, for instance:
132142
```json
@@ -148,3 +158,5 @@ Project settings in `.vscode/arduino.json`
148158
"port": "/dev/ttyUSB0"
149159
}
150160
```
161+
162+
### Global Tasks in vscode-arduino

src/arduino/arduino.ts

+22-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { arduinoChannel } from "../common/outputChannel";
2222
import { ArduinoWorkspace } from "../common/workspace";
2323
import { SerialMonitor } from "../serialmonitor/serialMonitor";
2424
import { UsbDetector } from "../serialmonitor/usbDetector";
25+
import { CCppProperties, CompilerCmdParser, CompilerCmdParserEngineGcc } from "./intellisense";
2526
import { ProgrammerManager } from "./programmerManager";
2627

2728
/**
@@ -268,7 +269,27 @@ export class ArduinoApp {
268269
arduinoChannel.show();
269270
// we need to return the result of verify
270271
try {
271-
await util.spawn(this._settings.commandPath, arduinoChannel.channel, args);
272+
const gccParserEngine = new CompilerCmdParserEngineGcc(dc.sketch);
273+
const compilerParser = new CompilerCmdParser([gccParserEngine]);
274+
275+
await util.spawn(this._settings.commandPath,
276+
arduinoChannel.channel,
277+
args,
278+
undefined,
279+
compilerParser.callback);
280+
281+
// Write compiler command parser result to IntelliSense
282+
// configuration file in case parsing was successful.
283+
if (compilerParser.result) {
284+
const cppPropsPath = path.join(ArduinoWorkspace.rootPath, constants.CPP_CONFIG_FILE);
285+
const cppProps = new CCppProperties(cppPropsPath);
286+
cppProps.merge(compilerParser.result);
287+
cppProps.write();
288+
arduinoChannel.info("IntelliSense configuration generated successfully.");
289+
} else {
290+
arduinoChannel.warning("Failed to generate IntelliSense configuration.");
291+
}
292+
272293
arduinoChannel.end(`Finished verify sketch - ${dc.sketch}${os.EOL}`);
273294
return true;
274295
} catch (reason) {
@@ -280,7 +301,6 @@ export class ArduinoApp {
280301
arduinoChannel.error(msg);
281302
return false;
282303
}
283-
284304
}
285305

286306
public tryToUpdateIncludePaths() {

0 commit comments

Comments
 (0)