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

Make it possible to define custom compiler keywords #6642

Open
denis-shienkov opened this issue Dec 8, 2020 · 14 comments
Open

Make it possible to define custom compiler keywords #6642

denis-shienkov opened this issue Dec 8, 2020 · 14 comments

Comments

@denis-shienkov
Copy link

denis-shienkov commented Dec 8, 2020

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.

@Colengms
Copy link
Collaborator

Colengms commented Dec 8, 2020

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

@denis-shienkov
Copy link
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 ?

@sean-mcmanus
Copy link
Collaborator

sean-mcmanus commented Dec 28, 2020

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.

@denis-shienkov
Copy link
Author

denis-shienkov commented Dec 29, 2020

Hi @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?

@sean-mcmanus
Copy link
Collaborator

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.

@denis-shienkov
Copy link
Author

denis-shienkov commented Dec 29, 2020

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.)

@denis-shienkov
Copy link
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).

@denis-shienkov
Copy link
Author

Also, it fails for the following combination:

изображение

изображение

@sean-mcmanus
Copy link
Collaborator

sean-mcmanus commented Dec 29, 2020

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.

@denis-shienkov
Copy link
Author

@sean-mcmanus ,

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

@github-actions
Copy link

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

@github-actions github-actions bot added the more votes needed Issues that have been postponed until more community members upvote it label Feb 28, 2021
@github-actions github-actions bot reopened this Dec 22, 2021
@github-actions github-actions bot modified the milestones: Triage, Backlog Dec 22, 2021
@github-actions
Copy link

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

@github-actions github-actions bot removed the more votes needed Issues that have been postponed until more community members upvote it label Dec 22, 2021
@slav4ocom
Copy link

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

@slav4ocom
Copy link

slav4ocom commented May 1, 2022

I found the way :)

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

and using is:

void Uart2Isr() __interrupt UART2_INT
{

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants