Skip to content

Make it possible to define custom compiler keywords #6642

Open

Description

@denis-shienkov

Type: LanguageService

Right now the intellisence fails at highliting of a custom compiler keywords, like __data, data, __xdata and so forth,
which are used, e.g. for 8051 (aka MCS51) architecture:

изображение

изображение

and so forth.

BTW, similar keywords also are exists and in many other compilers with different MCU architectures.

So, it would be good to allow to define the custom keywords in some VSCode API.

Activity

  1. Colengms commented on Dec 8, 2020

    @Colengms
    Contributor

    Hi denis-shienkov . Thanks for suggesting this. We will consider this for a future milestone.

  2. denis-shienkov commented on Dec 24, 2020

    @denis-shienkov
    Author

    Guys,

    1. as I understand, I can inject the required compiler keywords, using the grammars entry in the package.json file: https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide

    Someting like this:

    == package.json ==

        "grammars": [
          {
            "scopeName": "iar-keywords.injection",
            "path": "./syntaxes/iar-c-cpp.tmLanguage.json",
            "injectTo": [
              "source.c",
              "source.cpp"
            ]
          }
        ],
    

    == iar-c-cpp.tmLanguage.json ==

    {
        "scopeName": "iar-keywords.injection",
        "injectionSelector": "L:source.c, L:source.cpp",
        "patterns": [
            {
                "name": "keyword.c",
                "match": "(__aapcs_core)\\s"
            },
    }
    

    But, here I'm have a problem is that I need to do it dynamycally, e.g. I need to inject the appropriate keywords only for a specified compiler/architecture.

    For example, I will have a set of *.tmLanguage.json files for a different toolchains. But, seems, it is impossible to use
    the concrete *.tmLanguage.json file, because the grammars field has not any condition property, e.g. as when.

    Also, I can't to specify all *.tmLanguage.json files, because it is wrong.

    1. I found out a some additional API, called DocumentSemanticTokensProvider : https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide#semantic-token-provider

    But, here also it is unclear, how to use this provider to inject some additional compiler keywords to the document. F.e. I don't want to re-implement whole semantic features for every toolchain.

    I need only in ability to inject some additional compiler keywords depending on the current toolchain. Let's say, that I can detect the current used toolchain, it is not a problem here. A problem here is in injection...

    Guys, could you please point me, is it possible todo dynamically ?

  3. sean-mcmanus commented on Dec 28, 2020

    @sean-mcmanus
    Contributor

    FYI, those grammars will only affect lexical colorization, which is not implemented by our C/C++ extension, but by https://github.com/jeff-hykin/cpp-textmate-grammar (that might be a better place to file an issue like this). The IntelliSense parser won't have knowledge of the extra keywords and might generate error squiggles, which might be worked around via using something like

    #ifdef __INTELLISENSE__
    #define __bdata
    #endif
    

    in some file specified by the forcedInclude setting.

  4. denis-shienkov commented on Dec 29, 2020

    @denis-shienkov
    Author

    Hi Sean McManus (@sean-mcmanus) ,

    will only affect lexical colorization

    Ohh.. ok, clear, thanks.

    which might be worked around via using something like

    I have checked it already, and this does not work too. The intelliSence marks this keywords (with all expression) as error.

    Is there are other right way to insert a new keywords to the IntelliSense? Because this #ifdef is not soo good way...

    UPD: So, as I understand, is it not enough just to use the TextMate feature? I need also implement an additional steps and for the IntelliSense? Maybe is it possible to add some new API to the intelliSence, e.g. a new property which is an array of additional keywords or something else?

  5. sean-mcmanus commented on Dec 29, 2020

    @sean-mcmanus
    Contributor

    Can you give an example of IntelliSense giving an error with the keyword used? I'm not seeing an error:
    image

    Another alternative is to add the keywords to the "defines" section, like
    image

    Our IntelliSense engine doesn't currently have an extensibility model for adding keywords.

  6. denis-shienkov commented on Dec 29, 2020

    @denis-shienkov
    Author

    Can you give an example of IntelliSense giving an error with the keyword used? I'm not seeing an error:

    Yes, of course:

    изображение

    изображение

    Anyway, it is not an option to add the fake defines for that, because then the compilation can fails (and using the additional #ifdef __INTELLISENSE__ in many places is not good also.

    Also, how to define the @ symbol?

    Another alternative is to add the keywords to the "defines" section, like

    Could you please point me, what is a file with this section?

    Our IntelliSense engine doesn't currently have an extensibility model for adding keywords.

    That's a bad, bad, bad. ;) It would be good to have this feature (even better if it was possible to change dynamically from the typescript code.)

  7. denis-shienkov commented on Dec 29, 2020

    @denis-shienkov
    Author

    UPD: Yes, many thanks, for some compilers it will work:

    изображение

    But for other - will not work... Because there are impossible to use a fake defines for that (e.g. previous example with the @ symbol).

  8. denis-shienkov commented on Dec 29, 2020

    @denis-shienkov
    Author

    Also, it fails for the following combination:

    изображение

    изображение

  9. sean-mcmanus commented on Dec 29, 2020

    @sean-mcmanus
    Contributor

    The "@" case isn't part of the C++ standard language. Our compiler is currently only scoped to handle compilers based on gcc, clang, cl.exe, and EDG compilers that support the standard C++ language features (e.g. https://en.cppreference.com/w/cpp/compiler_support ). You would have to replace all @ occurrences with a macro that defines nothing if __INTELLISENSE__ is defined and uses @ otherwise. Our IntelliSense parser is based on https://www.edg.com/c -- so support for Keil extensions would need to originate from them, and from the list of customers at https://www.edg.com/customers, it looks like the Keil compiler is implemented using EDG as well, so the Keil team would need to somehow push their compiler changes back to the EDG team so other uses of EDG could benefit.

    The "defines" section I'm referring to is in c_cpp_properties.json or C_Cpp.default.defines.

    For the srf case, you would need to define it to something like "int" that would compile.

    We had a request to add Keil support, but it got closed due to not enough votes: #3222 ...you could file another request and we could see if it gets more votes.

  10. denis-shienkov commented on Dec 30, 2020

    @denis-shienkov
    Author

    Sean McManus (@sean-mcmanus) ,

    Ok, clear. Many thanks for your time and explanation.

  11. github-actions commented on Feb 28, 2021

    @github-actions

    This feature request is being closed due to insufficient upvotes. When enough upvotes are received, this issue will be eligible for our backlog.

  12. modified the milestones: Triage, Backlog on Dec 22, 2021
  13. github-actions commented on Dec 22, 2021

    @github-actions

    This feature request has received enough votes to be added to our backlog.

  14. removed
    more votes neededIssues that have been postponed until more community members upvote it
    on Dec 22, 2021
  15. slav4ocom commented on Apr 29, 2022

    @slav4ocom

    Helpfull information :) But in:
    void Uart2Isr() __interrupt (2)
    2 gets squiggless. How to avoid this ?

  16. slav4ocom commented on May 1, 2022

    @slav4ocom

    I found the way :)

    #define UART2_INT 8
    #ifdef __INTELLISENSE__
    #define UART2_INT
    #endif
    

    and using is:

    void Uart2Isr() __interrupt UART2_INT
    {
    
    }
    
  17. mrx23dot commented on Jul 11, 2024

    @mrx23dot

    try to make it empty

    #ifdef _MSC_VER
    #define __data
    #endif
    

    or more sophisticated

    // Macro to check if we are in VS Code
    #if defined(_MSC_VER) || defined(__GNUC__)
        #define IN_VSCODE (getenv("TERM_PROGRAM") && strcmp(getenv("TERM_PROGRAM"), "vscode") == 0)
    #else
        #define IN_VSCODE 0
    #endif
    
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions