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

Introduce a new regex for a special comment: howto? #863

Closed
wimalopaan opened this issue Dec 16, 2021 · 29 comments
Closed

Introduce a new regex for a special comment: howto? #863

wimalopaan opened this issue Dec 16, 2021 · 29 comments
Labels
bug Something isn't working

Comments

@wimalopaan
Copy link

I tried to introduce a special comment for CPP-directives like

#include "bla.lua"

in lua.tmLanguage.json

.vscode-oss/extensions/sumneko.lua-2.5.3/syntaxes

But now luck with

				{
						"begin": "^\\s*#[a-z]+",
						"beginCaptures": {
							"0": {
								"name": "punctuation.definition.comment.lua"
							}
						},
						"end": "\\n",
						"name": "comment.line.double-dash.lua"
					},

Maybe ralated too: https://github.com/sumneko/vscode-lua/issues/51
 
@sumneko
Copy link
Collaborator

sumneko commented Dec 16, 2021

I can't understand what you want, please tell more details

@wimalopaan
Copy link
Author

In some lua-file, e.g.

#include "bla.lua"
#define VALUE 42
local function test()
#ifdef DEBUG 
return 42;
#else
return 0;   
#end 
end

I want to use CPP-preprocessor directives like demonstrated above.
These should be

  1. first not disturb the parsing of the lua code
  2. be coloured in a special way.

I tried to achieve that with the above extension.

@sumneko
Copy link
Collaborator

sumneko commented Dec 16, 2021

@wimalopaan
Copy link
Author

Ok, thanks.

The plugin gets found, but no diffed.lua is created.

@wimalopaan
Copy link
Author

{
    "Lua.misc.parameters": [
        "--develop=true"
      ],

    "Lua.diagnostics.disable": [
        "undefined-global"
    ],
    "Lua.completion.displayContext": 2,
    "files.associations": {
        "*.lpp": "lua",
        "*.lh": "lua",
        "makefile.include": "makefile"
    },
    "Lua.diagnostics.globals": [
        "__libI",
        "errorCode",
        "__libD",
        "__libP",
        "__stopWmSw2",
        "__libA"
    ],
    "Lua.workspace.library": ["lib"],
    "files.autoSave": "afterDelay",
    "Lua.completion.showWord": "Enable",
    "Lua.diagnostics.libraryFiles": "Enable",
    "Lua.hint.enable": true,
    "Lua.color.mode": "SemanticEnhanced",
    "Lua.runtime.plugin": "/home/lmeier/Projekte/lua/plugin.lua",
}

@wimalopaan
Copy link
Author

Ok, works.

@wimalopaan
Copy link
Author

What about 2) ?

@sumneko
Copy link
Collaborator

sumneko commented Dec 16, 2021

You may try this: https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide#injection-grammars

EDIT: VSCode dose not supports 2) in one extension, you may create a new extension to do this

@wimalopaan
Copy link
Author

Wouldn't be sufficient to edit lua.tmLanguage.json?
Can you give me a hint to do that?

@sumneko
Copy link
Collaborator

sumneko commented Dec 16, 2021

Wouldn't be sufficient to edit lua.tmLanguage.json? Can you give me a hint to do that?

It is not good to modify internal files directly, because you need to modify it again after the new version is released.

You could replace # to // by plugin, then add // to Lua.runtime.nonstandardSymbol and set Lua.color.mode to Semantic or SemanticEnhanced

@wimalopaan
Copy link
Author

It is not good to modify internal files directly, because you need to modify it again after the new version is released.

Yes, I would go an patch approach.

You could replace # to // by plugin, then add // to Lua.runtime.nonstandardSymbol and set Lua.color.mode to Semantic or SemanticEnhanced

Why replace by // instead of -- as lua comment for the parser?

@sumneko
Copy link
Collaborator

sumneko commented Dec 16, 2021

Color of -- is parsed by tmLanguage.json (client side) , so it can not handle plugin.
Color of // is parsed by semantic-tokens language feature (server side), it can handle plugin.

@wimalopaan
Copy link
Author

Can I choose a speacial color for // then?

@sumneko
Copy link
Collaborator

sumneko commented Dec 16, 2021

"editor.semanticTokenColorCustomizations": {
    "rules": {
        "comment": "#ff0000"
    }
}

@wimalopaan
Copy link
Author

wimalopaan commented Dec 16, 2021

Mmh, does not work (should be red):

diffed.lua:

//include "../../global.h"

//ifdef INCLUDE_ANIMATIONS
//endif

local function run(event)
lcd.clear();
local x = 20;
local y = 20;

lcd.drawText(x, y, "Press ENTER", MIDSIZE);

if (event == EVT_VIRTUAL_ENTER) then
return 1;
else
return 0;
end
end

return {
run = run
};

settings.json:

{
    "editor.semanticTokenColorCustomizations": {
        "rules": {
                "comment": "#FF0000" 
        }
    },
    "Lua.misc.parameters": [
        "--develop=true"
      ],
    "Lua.diagnostics.disable": [
        "undefined-global"
    ],
    "Lua.completion.displayContext": 2,
    "files.associations": {
        "*.lpp": "lua",
        "*.lh": "lua",
        "makefile.include": "makefile"
    },
    "Lua.diagnostics.globals": [
        "__libI",
        "errorCode",
        "__libD",
        "__libP",
        "__stopWmSw2",
        "__libA"
    ],
    "Lua.workspace.library": ["lib"],
    "files.autoSave": "afterDelay",
    "Lua.completion.showWord": "Enable",
    "Lua.diagnostics.libraryFiles": "Enable",
    "Lua.hint.enable": true,
    "Lua.color.mode": "Semantic",
    "Lua.runtime.plugin": "/home/lmeier/Projekte/lua/plugin.lua",
    "Lua.runtime.nonstandardSymbol": ["//"]
}

@sumneko
Copy link
Collaborator

sumneko commented Dec 16, 2021

Try to reopen/scoll this file, the client may not refresh at the first time

@wimalopaan
Copy link
Author

No luck

@sumneko
Copy link
Collaborator

sumneko commented Dec 16, 2021

Try set editor.semanticHighlighting.enabled to true

@wimalopaan
Copy link
Author

As well no luck

@sumneko
Copy link
Collaborator

sumneko commented Dec 16, 2021

I have no idea, but I can confirm that it works at my side

@wimalopaan
Copy link
Author

Can you share your example?

@sumneko
Copy link
Collaborator

sumneko commented Dec 16, 2021

@wimalopaan
Copy link
Author

I'm using exaclty your example / plugin / setting ... no luck with color

@wimalopaan
Copy link
Author

Your example only works if main.lua has 5 lines. With 6 lines (blank) it does not work anymore

@wimalopaan
Copy link
Author

p1
p2

@sumneko
Copy link
Collaborator

sumneko commented Dec 16, 2021

Your example only works if main.lua has 5 lines. With 6 lines (blank) it does not work anymore

I can reproduce it with EOL LF.
If your environment allows, you can change EOL to CRLF to bypass this problem for now.

@sumneko sumneko added the bug Something isn't working label Dec 16, 2021
@wimalopaan
Copy link
Author

This is Linux, so LF only

@sumneko
Copy link
Collaborator

sumneko commented Dec 16, 2021

Maybe you can only waiting for fixing this bug or editing lua.tmLanguage.json first.
Notice that the getlen symbol (print(#array)) has used #, you must inject before it.

@wimalopaan
Copy link
Author

Maybe you can only waiting for fixing this bug or editing lua.tmLanguage.json first. Notice that the getlen symbol (print(#array)) has used #, you must inject before it.

Well, I have no real idea how to do that.

I hope you can fix that soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants