fortran-lang / vscode-fortran-support

Fortran language support for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=fortran-lang.linter-gfortran
MIT License
200 stars 30 forks source link

Highlighting of variables and functions with fortran keywords as name #401

Open plevold opened 2 years ago

plevold commented 2 years ago

Functions or variables named the same as a fortran keyword is highlighted differently than other functions or arrays in some situations. I appreciate that this might be a quite challenging task, but it would be really nice if the syntax highlighting could identify if the token is actually a reserved keyword or if it's a variable or function with the same name.

Screenshots image

Code sample

program main
    integer :: module
    integer :: if

    if = format()
    if (if == 1) then
        if (format() == 1) then
            module = 3
        end if
    end if

contains

    integer function format()
        format = 1
    end function
end program

To Reproduce Paste code above

Fortran Form Free form, but strictly speaking also fixed form

Build info (please complete the following information):

gnikit commented 2 years ago

@plevold thanks for the bug report. I will have a look, but I think it might be challenging to tell these two apart without a considerable performance hit. I will check it out

gnikit commented 2 years ago

I had a look at this and I am afraid the normal syntax highlighting will not suffice to solve this. As far as I can tell there is no way to create a regex that will distinguish between a user defined format and the format statement. For that we will need to use the AST scopes, luckily the language server knows about scopes but I will have to implement a semantics token provider to allow this.

This looks like it's going to be a pretty big piece of work so I won't probably get around to it for quite some time.

Divyansh200102 commented 4 months ago

@plevold is this issue still open?