Automatically changing typed syntax into the current language - vscode-extensions

There are so many minor syntaxes changes like .push() vs .append() and .count() vs .length() vs .size() vs len() that I'm having trouble remembering all the small changes between each language. Is there something, like a VSCode extension, that will automatically autocorrect to the chosen language?
For example if I type array.push() in python it will autocorrect to array.append() or if I do array.slice(1,2) it will autocorrect to array[1:2]|

Related

How to change a global variable name in an Excel VBA project?

If someone have to carry on working on an Excel VBA project/module after the previous developer left the company, how do they safely change a global variable name?
These global variable names can be problematic if they are misleading, misspelled, look like another variable, don't follow the chosen convention, etc.
Changing them with a Search/Replace is a problem because sometimes it's a word that appears in comments.
Changing them by Copy/Pasting is a problem because it's long and you can miss some, especially if there are a lot of occurrences or if you change it to something similar.
Is there a way to do this safely via the Excel "IDE", or via another tool?
What you need to do here is called a refactoring - you need to make a possibly dangerous change to the code, without affecting its behavior. Do it wrong and the code breaks!
Renaming an identifier that's used in one or more places, is a rename refactoring.
Most modern IDE's have such a feature (and several other refactorings). However the VBE was at the height of its glory well before Visual Studio was the full-featured tool it has become since then - heck, the VBE was Visual Studio (6.0) in 1998!
So you really have two options:
Do the refactoring manually - the IDE's search & replace functionality (Ctrl+H) can be dangerous here, because it treats code as simple text, without semantic understanding: you need to review every single occurrence individually, or risk renaming an identifier that was not referring to the variable you're trying to rename.
Use a 3rd-party tool - I don't know any VBIDE add-ins that understand the code deeply enough to allow safely refactoring VBA code, other than the open-source Rubberduck project, which I've managed since October 2014). This add-in parses your entire project, builds a symbol table, and lets you navigate and, yes, refactor/rename any identifier, automatically updating all call sites.
Note that Rubberduck is a very active open-source project, constantly improving. Parsing VBA is hard, and getting the VBE functionally on par with modern-day IDEs isn't a small undertaking, nor is it easy... but it's fun, and yep, it works.

Atom Syntax Grammar Names

I am working on a Language Package in Atom and am curious about how to name items. For some reason, things like keyword.operator.langname as the name, yet it still doesn't highlight. I checked the HTML source and the span is there, but no coloring. I even compared my code to other languages code and the styles.less file used in atom and it appears that it should work. What am I doing wrong?
Also, is there any good place that has a list of the selectors as I can't seem to find any docs on them.
The regex I am using for anyone who is curious is:
'match': ':',
'name': 'keyword.operator.langname'
(langname being a psuedonym for the name of the language.)
It's likely that the syntax theme you're using doesn't support it. I know that keyword.operator shows up in language-javascript, but when I look at one-dark-syntax as an example, the coloring for that class combination only exists in language-specific files. I feel like the best path for people designing small language packages is to look in core syntax theme packages to figure out which classes to use. Don't get too hung up on the actual class names, since your user won't see them at all unless they look at them in the dev tools.

IntelliJ: custom language: combine fragments in other languages

I am creating a custom language plugin for IntelliJ.
I would like it to be possible for a file in the new language to contain fragments of text in other languages.
The specific languages I would like to support are HTML, JS, CSS, and SQL.
I would also like to support other custom languages (i.e. languages I would define the syntax for).
The main feature I want is syntax coloring, but if I can get stuff like "go to declaration" and refactoring out of the box then all the better.
My last requirement is that it would be possible to use my own code to tell IntelliJ which language a fragment contains; fragments containing different languages will not be distinguishable at the lexer / parser level.
In short, I would like to implement something similar to what PhpStorm does when it detects, say, SQL inside a string:
I looked at IntelliJ's source code and found the ILazyParseableElementType interface which seemed relevant, but I'm not sure if this is the way to go (and if so - how to use it in my code exactly...)
Any pointers would be highly appreciated...
The Intellij feature/terminology you are looking for is Language Injections.
Here is a github PR which implements a very similar feature for JFLex files.
In short you need to implement a LanguageInjector and add it to your plugin.xml as a <languageInjector implementation="YourImplClass">.

Is it possible to display characters differently from what is stored on disk in Eclipse editor?

We're developing an Eclipse plugin.
When the user types <= I would like to display a left-arrow UTF character ⇐ instead.
The file on disk still needs to contain the original "less than,equals" symbols, because that is what the programming language prescribes.
In other contexts, in the same editor, I might want to display the same character sequence <= as unicode less or equal ≤. This would help the user understand how the compiler interprets the sequence <=, depending on the context. Again, the document (and file) should not be changed, only the way we display it.
What is the easiest way to do this? Note that we're already on xText, so we use the editor provided by xText.
Eclipse text editors normally use an object implementing IDocument (usually also the numerous IDocumentExtensionXX interfaces) often by extending the AbstractDocument class.
This document class provides the text that the editor displays and is updated with the changes the user makes, so it should be able to manage converting between the file and display representations.

Domain specific language IDE

I've recently developed a domain-specific language using flex and bison. I would like to create a user interface for editing script files using this language. In particular I would like to have common functionalities such as file handling, menus, buttons, syntax highlighting, error checking and so on. Do you know any tool which can be used to develop such kind of application? I would prefer one which can give me a prototype rapidly.
such as file handling, menus, buttons, syntax highlighting, error
checking
I think that file handling, menus, buttons and highlighting are your least concerns. What you call "error checking" on the other hand. That can be a tough nut. I will try to give you some pointers to how you can (in a somewhat primitive manner) detect errors on the fly as the user inputs source code in the editor.
I assume you wish for something like Eclipses (for java at least) real time analysis of the written code in the editor? I'm not familiar with how Eclipse work internally but this is probably done by some pre-compilation process that processes all source code again and again as you change it.
One way to prototype this (and indeed build a non-prototype as well) would be to use Flex and Bison, and I notice you already is familiar with these tools. You can build you grammar and create action code for all interesting parts so you can find syntax deviations fairly easy. After this you make your editor run the flex and bison generated c-code as the user writes the source code in you IDE and have some way of displaying the output. Either in a terminal-like status window or directly in the text-editing field (as Eclipse does) (the latter case is probably a pain to build but by no means impossible and would give you IDE a professional touch).
Suppose you would like to build an IDE for ADA 95 the following Flex and Bison (Actually Lex and Yacc) code could help you do exactly this (it's a decent syntax analyzer that reports errors (what and where)):
http://www.adaic.org/resources/add_content/standards/95lrm/lexer9x.l
http://www.adaic.org/resources/add_content/standards/95lrm/grammar9x.y
Hope this helps.
Edit:
to have cool error highlighting and such in the text-editor field of your IDE you could let your bison generated syntax analyser generate something thats easy to parse, like XML, that contains the type of error and where it lies (row and column for example) and then use that to display the errors... you simply embed an XML parser in the IDE (lots of free one available) and extract the data you need and change the display accordingly... That shouldn't be rocket science when I think about it.