Autodesk-AutoCAD / AutoLispExt

Visual Studio Code Extension for AutoCAD® AutoLISP
https://marketplace.visualstudio.com/items?itemName=Autodesk.autolispext
Apache License 2.0
83 stars 29 forks source link

.Net Symbol Coloring #21

Open JD-Howard opened 3 years ago

JD-Howard commented 3 years ago

The original VLIDE would color function definitions created using .Net and I would like to see this ability get carried over to this Extension.

Describe the solution you'd like Preferably to colorize all function names that exist in the global scope of the active AutoCAD document, but special ones defined by .Net or Arx would be especially helpful in a different color to identify stuff I can't do anything about from lisp.

Describe alternatives you've considered Debugger currently sees these symbols as <EXRXSUBR> functions if you mouse over them. If it isn't that difficult to only colorize them while in debug mode that would be okay too. My own research into dynamic coloring hasn't gone very well, so I don't know how viable this is in general.

image

hualin-wu-2000 commented 3 years ago

I don't understand what the symbol .Net defined. You mean the function is a call back defined in C# codes (like the above NS:ACAD:LISTBOX)?

JD-Howard commented 3 years ago

Yes, [LispFunction("NS:ACAD:ListBox")] is one of my .Net user input functions that takes CSV data and presents it in a table format. I used to get a nice color pop for those functions in the old VLIDE, but I currently don't in VSCode.

I think I'd like to see the .Net & Arx functions colored the exact same as all the Native functions like LIST, CDR, and we'll just color Lisp defined DEFUN's with something else. That would accomplish my goal of identifying the things "I can't do anything about from Lisp" comment.

hualin-wu-2000 commented 3 years ago

it looks like we need a powerful syntax highlight here: https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide

And how do you know this is a user defined lisp function but don't find its implementation body, and this is a .Net defined function?

JD-Howard commented 3 years ago

Thanks for the link, that page looks familiar, I may have tinkered around with their top concept at one point, but I think I moved on to the sections about "language servers" too fast because it seemed to do more of the things I was trying to do at the time. I do wonder if their documentation recently evolved. Looking at your link and this one, I'd swear there is better information on these topics now. Maybe I just have a better baseline now; IDK https://code.visualstudio.com/api/language-extensions/programmatic-language-features

Anyway, I think the answer to your question is the context I laid out in this statement:

to colorize all function names that exist in the global scope of the active AutoCAD document

I don't know how we query all available symbols and their (type 'symbol) values, but that would be required context.

morbius1st commented 3 years ago

JD I found the syntax colorization ability in the extension a bit lacking. I made my own language syntax file that better divides the language into its syntax components. The attached shows all (I think all) of the different parts that can be individually colored. The colors in this are just to help tell the parts apart - they can all be changed. Does this provide what you are looking for? I can provide if you are interested and I'd be happy to provide to AutoDesk if they are interested. Language-Diagram.pdf

JD-Howard commented 3 years ago

I don't know about Autodesk, but I would be interested in seeing your language files if you don't mind sharing them. I don't suspect they would want to entirely swap ours out because they are clearly "based" on something they considered a source of truth. However, I am also certain there is great potential for me to learn something that would help evolve ours too.

morbius1st commented 3 years ago

No problem – please see the attached.

Being a bit lazy, in order to implement my changes, I replaced AutoDesk’s syntax file with my own. This means I get all of the Autodesk features + my syntax colorizations.

Make a backup before you change anything of course.

In order to do this, replace this file:

C:\Users{your user name}.vscode\extensions\autodesk.autolispext-1.3.0\extension\syntaxes\ autolisp.tmLanguage.json

With the attached file.

Note that I’ve never written this type of code before so I may have made some mistakes that have not shown up yet. Let me know how this works out for you and let me know what you think.

In terns of the basis for their language file – it is not based on anything. There are several examples of this type of file online and none are this simplistic.

Also, I have taken the position that this the language file does not do language checking. I feel that the purpose for the language file is to parse the syntax and provide the tokens to allow colorization. Using the language correctly is up to AutoCAD. That is, if you use a wrong keyword, it will get colorized as if it is correct but AutoCAD will reject the usage. For this reason, the language file does not include all of the Lisp keywords like AutoDesk’s and other versions do. This makes the file smaller and faster. The exceptions are those keywords I wanted to highlight special.

The below provides the language colorizations per my PDF – all you need to do is adjust the colors below. This snippet goes into your package.json settings file.

"editor.tokenColorCustomizations": {
    "textMateRules": [
                                         {
                                                        "scope": "punctuation.definition.comment",
                                                        "settings": {
                                                                       "foreground": "#2e473d"
                                                        }
                                         },
                                         {
                                                        "scope": "comment.line",
                                                        "settings": {
                                                                       "foreground": "#15412f"
                                                        }
                                         },
                                         {
                                                        "scope": "comment.block",
                                                        "settings": {
                                                                      "foreground": "#454d49"
                                                        }
                                         },
                                         {
                                                        "scope": "keyword",
                                                        "settings": {
                                                                       "foreground": "#dde000"
                                                        }
                                         },
                                         {
                                                        "scope": "keyword.arithmetic",
                                                        "settings": {
                                                                       "foreground": "#726ffa"
                                                        }
                                         },
                                         {
                                                        "scope": "keyword.other",
                                                        "settings": {
                                                                       "foreground": "#87fa52"
                                                        }
                                         },
                                         {
                                                        "scope": "keyword.error.language",
                                                        "settings": {
                                                                       "foreground": "#ff002b"
                                                        }
                                         },            
                                         {
                                                        "scope": "keyword.control.logical",
                                                        "settings": {
                                                                       "foreground": "#a052fa"
                                                        }
                                         },
                                         {
                                                        "scope": "keyword.operator.logical",
                                                        "settings": {
                                                                       "foreground": "#60dab5"
                                                        }
                                         },
                                         {
                                                        "scope": "keyword.operator.arithmetic",
                                                        "settings": {
                                                                       "foreground": "#fa52c2"
                                                        }
                                         },
                                         {
                                                        "scope": "keyword.operator.other",
                                                        "settings": {
                                                                       "foreground": "#fae152"
                                                        }
                                         },
                                         {
                                                        "scope": "punctuation.definition.quote",
                                                        "settings": {
                                                                       "foreground": "#53e5ff"
                                                        }
                                         },
                                         {
                                                        "scope": "constant.character.escape",
                                                        "settings": {
                                                                       "foreground": "#53e5ff"
                                                        }
                                         },
                                         {
                                                        "scope": "constant.language",
                                                        "settings": {
                                                                       "foreground": "#59ff53"
                                                        }
                                         },
                                         {
                                                        "scope": "constant.language.equality",
                                                        "settings": {
                                                                       "foreground": "#ff7300"
                                                        }
                                         },
                                         {
                                                        "scope": "support.other.language",
                                                        "settings": {
                                                                       "foreground": "#ff0000"
                                                        }
                                         },
                                         {
                                                        "scope": "entity.name.variable.parameter",
                                                        "settings": {
                                                                       "foreground": "#927470"
                                                        }
                                         },
                                         {
                                                        "scope": "entity.name.variable",
                                                        "settings": {
                                                                       "foreground": "#cc4432"
                                                        }
                                         },
                                         {
                                                        "scope": "entity.name.class",
                                                        "settings": {
                                                                       "foreground": "#f233f8"
                                                        }
                                         },                                          
                                         {
                                                        "scope": "punctuation.definition.block",
                                                        "settings": {
                                                                       "foreground": "#144bff"
                                                        }
                                         },
                                         {
                                                        "scope": "punctuation.definition.parameter.divider",
                                                        "settings": {
                                                                       "foreground": "#14bcff"
                                                        }
                                         },
]
},

"files.associations": {
    "*.lsp": "autolisp"
},
"[autolisp]": {
           },

Jeff

JD-Howard commented 3 years ago

Jeff, could you please edit this in GitHub to add your file attachment. Probably a good idea to remove the fluff that includes your email address too.

morbius1st commented 3 years ago

JD, uploaded as requested autolisp.tmLanguage.zip

edited response also.

JD-Howard commented 3 years ago

Thanks Jeff, That certainly does pick up some highlighting we are missing. I've got about 5-8 PR's already planned, but Language Server stuff is definitively on my agenda. I will analyze this in greater detail and see what makes sense to apply without inadvertently masking underdeveloped features.

morbius1st commented 3 years ago

no problem - glad it helps. A language server would definitely be a good way to go as that would allow a more holistic view of a lisp project. personally, I would like to see better formatting options. I very much dislike deep indenting of code so that it aligns with its beginning - if that makes sense.. on an alternate note, do you use code map so that you can get a list of the individual functions within a single lisp file? I wrote a setting for that that also provides headings in the function list

JD-Howard commented 3 years ago

I agree on a desire to have more formatting options. Adding what I'd call the VLIDE classic version is on my radar, but a tiny little blip at the moment.

Autodesk had a very strong foundation for mapping an LSP, I've just been building/exposing some additional research data points. Which is why those next 5-8 PR's will be including badly needed fancy things like better auto-completion, function signatures, F12 GotoDefinition and localizing a selected global variable.

hualin-wu-2000 commented 3 years ago

Hi Jeff,

>>I very much dislike deep indenting of code so that it aligns with its beginning - if that makes sense.. on an alternate note, do you use code map so that you can get a list of the individual functions within a single lisp file? I wrote a setting for that that also provides headings in the function list Please create an issue in this repo for your expectation. And Autodesk are welcoming any contribution.

thanks

morbius1st commented 3 years ago

I found an error in the syntax file - parameters were not completely being broken out. The attached fixes this. autolisp.tmLanguage.zip