microhobby / linuxkerneldev

Visual Studio Code extension to help find documentation, device tree matching on device driver source code, by compatible strings
MIT License
42 stars 9 forks source link

Aliases symbols does not match files on lookup #10

Closed vindicatorr closed 1 year ago

vindicatorr commented 3 years ago

As I'm learning to use zephyr (rtos) and starting to get into device-trees, I looked at the extensions in vscode and came across yours. The first test I did was to look up led0 from ./samples/basic/blink/src/main.c.

vscode-ctags: enqueing lookup: "led0".
vscode-ctags: "led0" has 77 matches.

However, ./boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts was not among the list:

    leds {
        compatible = "gpio-leds";
        led0_green: led_0 {
            gpios = <&gpio0 6 GPIO_ACTIVE_LOW>;
            label = "Green LED 0";
        };
        led1_red: led_1 {
            gpios = <&gpio0 8 GPIO_ACTIVE_LOW>;
            label = "Red LED 1";
        };
        led1_green: led_2 {
            gpios = <&gpio1 9 GPIO_ACTIVE_LOW>;
            label = "Green LED 1";
        };
        led1_blue: led_3 {
            gpios = <&gpio0 12 GPIO_ACTIVE_LOW>;
            label = "Blue LED 1";
        };
    };

    aliases {
        sw0 = &button0;
        led0 = &led0_green;
        led1 = &led1_red;
        led2 = &led1_green;
        led3 = &led1_blue;
        led0-green = &led0_green;
        led1-red   = &led1_red;
        led1-green = &led1_green;
        led1-blue  = &led1_blue;
        pwm-led0 = &red_pwm_led;
        pwm-led1 = &green_pwm_led;
        pwm-led2 = &blue_pwm_led;
        red-pwm-led = &red_pwm_led;
        green-pwm-led = &green_pwm_led;
        blue-pwm-led = &blue_pwm_led;
    };

NoDongle_Screenshot_20211026_112857

EDIT0: I replaced the embedded image because I originally uploaded the one that had vscode definition results, which by the way has the same result your extension does (missing the above dongle).

microhobby commented 3 years ago

Hi @vindicatorr , first of all thanks for the report. Did you already checked the extension for Zephyr: https://marketplace.visualstudio.com/items?itemName=trond-snekvik.devicetree

I think this extension will give you better results as it is aimed directly to Zephyr. Let me know.

vindicatorr commented 3 years ago

Oh yeah. I think I had that installed at one point, but removed it when I saw it was require west. I was wanting to just use cmake directly, but it is so painful without west.

I'm checking it out again. From what I was able to tell so far, is that zephyr doesn't support the esp32c3 well at all when I was going through the device tree. Lots of things missing and incorrect values. Depending on how quickly I learn about the device-trees and if I can whip something out based on the technical reference manual for the c3, I may just stick with esp-idf. The zephyr (particularly regarding device trees) and c3 technical docs seem good, but are lengthy, and there's a bunch of components involved, that I'm not sure where to start. I'm sure it's all there, and I just have to figure out how to put it all together.

microhobby commented 3 years ago

@vindicatorr I tried to reproduce in the last version and it's working ok. If I add a symbol led0 on the ./samples/basic/blink/src/main.c and lookup for it the boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts is listed.

vindicatorr commented 3 years ago

Well now that's odd, I upgraded, but am not seeing ANY output for CTAGS. And when I manually try to run Ctags Support: regenerate tags file, I get:

Command 'Ctags Support: regenerate tags file' resulted in an error (command 'embeddedLinuxDev.regenerateCTags' not found)

AH! I see the error in the Extension Host output. I'll create an issue for that.

EDIT0: Filled in something I missed.

microhobby commented 3 years ago

@vindicatorr thanks for the report, I have a fix for this activation issue being published right now. should be available for update in a few minutes

microhobby commented 3 years ago

@vindicatorr is published now v0.4.2, let me know if this works for you

vindicatorr commented 3 years ago

Weird, I was refreshing the extension section, but it only showed the update when I reloaded the window. Initially it failed with:

[2021-11-05 19:18:19.665] [exthost] [error] [microhobby.linuxkerneldev] provider FAILED
[2021-11-05 19:18:19.665] [exthost] [error] TypeError: Cannot read property 'entries' of undefined
    at DTSEngine.<anonymous> (/home/userName/.vscode-insiders/extensions/microhobby.linuxkerneldev-0.4.2/out/DTSEngine.js:1494:57)
    at Generator.next (<anonymous>)
    at fulfilled (/home/userName/.vscode-insiders/extensions/microhobby.linuxkerneldev-0.4.2/out/DTSEngine.js:5:58)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

But after I closed vscode and re-opened it, the extension ran, but... I'm currently being flooded with vscode-ctags: changed extension-output-#2 Log:

vscode-ctags: extension activated.
vscode-ctags: changed extHostLog log
vscode-ctags: changed extHostLog log
vscode-ctags: found existing tags file.
vscode-ctags: changed extHostLog log
vscode-ctags: changed extHostLog log
vscode-ctags: opened <pathTo>/zephyr/boards/arm/nrf52840dongle_nrf52840/fstab-stock.dts dts
vscode-ctags: changed extHostLog log
vscode-ctags: opened <pathTo>/zephyr/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts.git plaintext
vscode-ctags: opened extension-output-#9 Log
vscode-ctags: opened extension-output-#12 Log
vscode-ctags: changed extension-output-#12 Log
vscode-ctags: indexed tags.
vscode-ctags: opened extension-output-#2 Log
vscode-ctags: changed extension-output-#2 Log
...//being spammed with the last log entry.

EDIT0: Scrolling through I did see some other entries like vscode-ctags: activaded extension-output-#2 Log and

vscode-ctags: changed extension-output-#2 Log
vscode-ctags: changed <pathTo>/zephyr/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts dts
vscode-ctags: changed <pathTo>/zephyr/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts dts
vscode-ctags: saved <pathTo>/zephyr/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts dts

But they weren't exactly being spammed (even though there are a small number of those entries) like the extension-output spam.

microhobby commented 3 years ago

@vindicatorr are you enabling the new experimental features? If so, I don't recommend it for Zephyr projects, it's not tested. For your use the ctags is the recommended. I tried to reproduce your problem with ctags and the file was listed.

microhobby commented 3 years ago

@vindicatorr another question, would you have two workspaces open? From the "Add Folder to Workspace..." option

vindicatorr commented 3 years ago

It WAS enabled. I disabled it in the settings GUI, but didn't see any corresponding entry in the json file which I found odd. I closed/reopened, and still nothing, yet the GUI entry was still disabled. For good measure I also set the json entry.

I didn't even know the difference between ctags and the "experimental features".

But even with the setting disabled in GUI/json, I'm still getting spammed the moment I switch to the dts file:

vscode-ctags: extension activated.
vscode-ctags: found existing tags file.
vscode-ctags: indexed tags.
vscode-ctags: opened <pathTo>/zephyr/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts.git plaintext
vscode-ctags: opened extension-output-#12 Log
vscode-ctags: changed extension-output-#12 Log
vscode-ctags: changed extension-output-#12 Log
vindicatorr commented 3 years ago

Nope, only one workspace. I just File->Open Folder and pointed to the zephyr folder I cloned.

microhobby commented 3 years ago

It WAS enabled. I disabled it in the settings GUI, but didn't see any corresponding entry in the json file which I found odd. I closed/reopened, and still nothing, yet the GUI entry was still disabled. For good measure I also set the json entry.

I didn't even know the difference between ctags and the "experimental features".

But even with the setting disabled in GUI/json, I'm still getting spammed the moment I switch to the dts file:

vscode-ctags: extension activated.
vscode-ctags: found existing tags file.
vscode-ctags: indexed tags.
vscode-ctags: opened <pathTo>/zephyr/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts.git plaintext
vscode-ctags: opened extension-output-#12 Log
vscode-ctags: changed extension-output-#12 Log
vscode-ctags: changed extension-output-#12 Log

hmm, ok. Besides the logs the lookup is giving you some results or nothing? Thanks for your patience and help.

vindicatorr commented 3 years ago

I also meant to ask if there's a reason why there are 2 locations in settings for your extension: Linux Kernel dev and Universal CTags? I'd think you'd want the entries consolidated under a common name(/space?) like linuxkerneldev. So something like linuxkerneldev.kerneldev.experimental..,. and linuxkerneldev.ctags.....

microhobby commented 3 years ago

I also meant to ask if there's a reason why there are 2 locations in settings for your extension: Linux Kernel dev and Universal CTags? I'd think you'd want the entries consolidated under a common name(/space?) like linuxkerneldev. So something like linuxkerneldev.kerneldev.experimental..,. and linuxkerneldev.ctags.....

just because it's a legacy of the universal ctags extension that I forked, but I agree that this should be changed. Would you mind opening an issue for that? I would appreciate

vindicatorr commented 3 years ago

To answer your earlier question, no. It isn't being found:

vscode-ctags: extension activated.
vscode-ctags: found existing tags file.
vscode-ctags: enqueing lookup: "led_0".
vscode-ctags: enqueing lookup: "led_0".
vscode-ctags: enqueing lookup: "led_0".
vscode-ctags: opened /settings/user jsonc
vscode-ctags: opened <pathTo>/zephyr/boards/arm/nrf52840dongle_nrf52840/nrf52840dongle_nrf52840.dts.git plaintext
vscode-ctags: opened /settings/resourceLanguage jsonc
vscode-ctags: opened /ignoredSettings jsonc
vscode-ctags: opened /launch jsonc
vscode-ctags: opened /token-styling jsonc
vscode-ctags: opened /textmate-colors jsonc
vscode-ctags: opened /workbench-colors jsonc
vscode-ctags: enqueing lookup: "/*
 * Copyright (c) 2018 Nordic Semiconductor ASA
 * Copyright (c) 2017 Linaro Limited
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/dts-v1/;
#include <nordic/nrf52840_qiaa.dtsi>

/ {
    model = "Nordic nRF52840 Dongle NRF52840";
    compatible = "nordic,nrf52840-dongle-nrf52840";

    chosen {
        zephyr,console = &uart0;
        zephyr,shell-uart = &uart0;
        zephyr,uart-mcumgr = &uart0;
        zephyr,bt-mon-uart = &uart0;
        zephyr,bt-c2h-uart = &uart0;
        zephyr,sram = &sram0;
        zephyr,flash = &flash0;
        zephyr,code-partition = &slot0_partition;
    };

    leds {
        compatible = "gpio-leds";
        led0_green: led_0 {
            gpios = <&gpio0 6 GPIO_ACTIVE_LOW>;
            label = "Green LED 0";
        };
        led1_red: led_1 {
            gpios = <&gpio0 8 GPIO_ACTIVE_LOW>;
            label = "Red LED 1";
        };
        led1_green: led_2 {
            gpios = <&gpio1 9 GPIO_ACTIVE_LOW>;
            label = "Green LED 1";
        };
        led1_blue: led_3 {
            gpios = <&gpio0 12 GPIO_ACTIVE_LOW>;
            label = "Blue LED 1";
        };
    };

    pwmleds {
        compatible = "pwm-leds";
        red_pwm_led: pwm_led_0 {
            pwms = <&pwm0 8>;
        };
        green_pwm_led: pwm_led_1 {
            pwms = <&pwm0 41>;
        };
        blue_pwm_led: pwm_led_2 {
            pwms = <&pwm0 12>;
        };
    };

    buttons {
        compatible = "gpio-keys";
        button0: button_0 {
            gpios = <&gpio1 6 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
            label = "Push button switch 0";
        };
    };

    /* These aliases are provided for compatibility with samples */
    aliases {
        sw0 = &button0;
        led0 = &led0_green;
        led1 = &led1_red;
        led2 = &led1_green;
        led3 = &led1_blue;
        led0-green = &led0_green;
        led1-red   = &led1_red;
        led1-green = &led1_green;
        led1-blue  = &led1_blue;
        pwm-led0 = &red_pwm_led;
        pwm-led1 = &green_pwm_led;
        pwm-led2 = &blue_pwm_led;
        red-pwm-led = &red_pwm_led;
        green-pwm-led = &green_pwm_led;
        blue-pwm-led = &blue_pwm_led;
    };
};

&adc {
    status = "okay";
};

&gpiote {
    status = "okay";
};

&gpio0 {
    status = "okay";
};

&gpio1 {
    status = "okay";
};

&uart0 {
    compatible = "nordic,nrf-uarte";
    status = "okay";
    current-speed = <115200>;
    tx-pin = <20>;
    rx-pin = <24>;
    rx-pull-up;
    rts-pin = <17>;
    cts-pin = <22>;
    cts-pull-up;
};

&i2c0 {
    compatible = "nordic,nrf-twi";
    status = "okay";
    sda-pin = <26>;
    scl-pin = <27>;
};

&i2c1 {
    compatible = "nordic,nrf-twi";
    /* Cannot be used together with spi1. */
    /* status = "okay"; */
    sda-pin = <30>;
    scl-pin = <31>;
};

&pwm0 {
    status = "okay";
    ch0-pin = <8>;
    ch0-inverted;
    ch1-pin = <41>;
    ch1-inverted;
    ch2-pin = <12>;
    ch2-inverted;
};

/*
 * By default, not adding all available SPI instances (spi2, spi3) due to
 * limited GPIOs available on dongle board.
 */
&spi0 {
    compatible = "nordic,nrf-spi";
    /* Cannot be used together with i2c0. */
    /* status = "okay"; */
    sck-pin = <27>;
    mosi-pin = <26>;
    miso-pin = <42>;
};

&spi1 {
    compatible = "nordic,nrf-spi";
    status = "okay";
    sck-pin = <31>;
    mosi-pin = <30>;
    miso-pin = <45>;
};

/* Include flash partition table.
 * Two partition tables are available:
 * fstab-stock      -compatible with Nordic nRF5 bootloader, default
 * fstab-debugger   -to use an external debugger, w/o the nRF5 bootloader
 */
#include "fstab-stock.dts"

zephyr_udc0: &usbd {
    compatible = "nordic,nrf-usbd";
    status = "okay";
};
".
vscode-ctags: enqueing lookup: "led_0".
vscode-ctags: opened extension-output-#8 Log
vscode-ctags: indexed tags.
vscode-ctags: "led_0" has no matches.
vscode-ctags: "led_0" has no matches.
vscode-ctags: "led_0" has no matches.
vscode-ctags: "/*
 * Copyright (c) 2018 Nordic Semiconductor ASA
 * Copyright (c) 2017 Linaro Limited
 *
 * SPDX-License-Identifier: Apache-2.0
 */

/dts-v1/;
#include <nordic/nrf52840_qiaa.dtsi>

/ {
    model = "Nordic nRF52840 Dongle NRF52840";
    compatible = "nordic,nrf52840-dongle-nrf52840";

    chosen {
        zephyr,console = &uart0;
        zephyr,shell-uart = &uart0;
        zephyr,uart-mcumgr = &uart0;
        zephyr,bt-mon-uart = &uart0;
        zephyr,bt-c2h-uart = &uart0;
        zephyr,sram = &sram0;
        zephyr,flash = &flash0;
        zephyr,code-partition = &slot0_partition;
    };

    leds {
        compatible = "gpio-leds";
        led0_green: led_0 {
            gpios = <&gpio0 6 GPIO_ACTIVE_LOW>;
            label = "Green LED 0";
        };
        led1_red: led_1 {
            gpios = <&gpio0 8 GPIO_ACTIVE_LOW>;
            label = "Red LED 1";
        };
        led1_green: led_2 {
            gpios = <&gpio1 9 GPIO_ACTIVE_LOW>;
            label = "Green LED 1";
        };
        led1_blue: led_3 {
            gpios = <&gpio0 12 GPIO_ACTIVE_LOW>;
            label = "Blue LED 1";
        };
    };

    pwmleds {
        compatible = "pwm-leds";
        red_pwm_led: pwm_led_0 {
            pwms = <&pwm0 8>;
        };
        green_pwm_led: pwm_led_1 {
            pwms = <&pwm0 41>;
        };
        blue_pwm_led: pwm_led_2 {
            pwms = <&pwm0 12>;
        };
    };

    buttons {
        compatible = "gpio-keys";
        button0: button_0 {
            gpios = <&gpio1 6 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
            label = "Push button switch 0";
        };
    };

    /* These aliases are provided for compatibility with samples */
    aliases {
        sw0 = &button0;
        led0 = &led0_green;
        led1 = &led1_red;
        led2 = &led1_green;
        led3 = &led1_blue;
        led0-green = &led0_green;
        led1-red   = &led1_red;
        led1-green = &led1_green;
        led1-blue  = &led1_blue;
        pwm-led0 = &red_pwm_led;
        pwm-led1 = &green_pwm_led;
        pwm-led2 = &blue_pwm_led;
        red-pwm-led = &red_pwm_led;
        green-pwm-led = &green_pwm_led;
        blue-pwm-led = &blue_pwm_led;
    };
};

&adc {
    status = "okay";
};

&gpiote {
    status = "okay";
};

&gpio0 {
    status = "okay";
};

&gpio1 {
    status = "okay";
};

&uart0 {
    compatible = "nordic,nrf-uarte";
    status = "okay";
    current-speed = <115200>;
    tx-pin = <20>;
    rx-pin = <24>;
    rx-pull-up;
    rts-pin = <17>;
    cts-pin = <22>;
    cts-pull-up;
};

&i2c0 {
    compatible = "nordic,nrf-twi";
    status = "okay";
    sda-pin = <26>;
    scl-pin = <27>;
};

&i2c1 {
    compatible = "nordic,nrf-twi";
    /* Cannot be used together with spi1. */
    /* status = "okay"; */
    sda-pin = <30>;
    scl-pin = <31>;
};

&pwm0 {
    status = "okay";
    ch0-pin = <8>;
    ch0-inverted;
    ch1-pin = <41>;
    ch1-inverted;
    ch2-pin = <12>;
    ch2-inverted;
};

/*
 * By default, not adding all available SPI instances (spi2, spi3) due to
 * limited GPIOs available on dongle board.
 */
&spi0 {
    compatible = "nordic,nrf-spi";
    /* Cannot be used together with i2c0. */
    /* status = "okay"; */
    sck-pin = <27>;
    mosi-pin = <26>;
    miso-pin = <42>;
};

&spi1 {
    compatible = "nordic,nrf-spi";
    status = "okay";
    sck-pin = <31>;
    mosi-pin = <30>;
    miso-pin = <45>;
};

/* Include flash partition table.
 * Two partition tables are available:
 * fstab-stock      -compatible with Nordic nRF5 bootloader, default
 * fstab-debugger   -to use an external debugger, w/o the nRF5 bootloader
 */
#include "fstab-stock.dts"

zephyr_udc0: &usbd {
    compatible = "nordic,nrf-usbd";
    status = "okay";
};
" has no matches.
vscode-ctags: "led_0" has no matches.
vscode-ctags: enqueing lookup: "led_0".
vscode-ctags: "led_0" has no matches.
vscode-ctags: opened extension-output-#11 Log
vscode-ctags: opened extension-output-#12 Log
vscode-ctags: changed extension-output-#12 Log
vscode-ctags: opened extension-output-#2 Log
vscode-ctags: changed extension-output-#2 Log
vscode-ctags: changed extension-output-#2 Log
microhobby commented 3 years ago

@vindicatorr ok, I had tried with the symbol led0 that is the alias for &led0_green label. led_0 is a node name, apparently ctags is doing the lookup only to labels. I will investigate this case.

vindicatorr commented 3 years ago

Yeah, if I hover over the LED0 alias, it shows the 6 possible locations, but I don't know if any of them are applicable.

I was also just toying with other stuff and was hit with /home/userName/.vscode-insiders/extensions/microhobby.linuxkerneldev-0.4.2/scripts/findDeviceTreeMatch.sh: line 12: code-insiders: command not found and I get Not found match for gpio-keys 😢 (Embedded Linux Dev) when trying to do Device Tree Doc from compatible even though I had set:

    "devicetree.bindings": [        
        "${workspaceFolder}/dts/bindings"
    ],

which contains gpio-keys.yaml

EDIT0: "leds"->"keys"

microhobby commented 3 years ago

Yeah, if I hover over the LED0 alias, it shows the 6 possible locations, but I don't know if any of them are applicable.

I was also just toying with other stuff and was hit with /home/userName/.vscode-insiders/extensions/microhobby.linuxkerneldev-0.4.2/scripts/findDeviceTreeMatch.sh: line 12: code-insiders: command not found and I get Not found match for gpio-keys 😢 (Embedded Linux Dev) when trying to do Device Tree Doc from compatible even though I had set:

    "devicetree.bindings": [        
        "${workspaceFolder}/dts/bindings"
    ],

which contains gpio-keys.yaml

EDIT0: "leds"->"keys"

yeah yeah, these features are not ready for Zephyr 😅, the path for these are hard coded. Would you mind open another issue to address this?

microhobby commented 1 year ago

@vindicatorr sorry but I'm deciding to leave Zephyr issues out of the scope of this extension, since we have an extension dedicated for Zephyr and I do not have time to address these.