VS Code - Text formatting in a new language extension - visual-studio-code

I'm building an extension providing a syntax highlighting for the 'Jack' language used in an online course I am taking (Nand2Tetris at Coursera - it is not a part of the course assignment). I have the syntax highlighting rules ready, but I would like to add custom formatting for some language elements. In particular, I would like type definitions to appear in italic.
I know how to change the user settings to get the desired result on my VS Code installation, but I would like that formatting to be the default behavior for anyone using the extension.
I've tried to create a new theme extension and then copy paste the 'themes' folder from it to the 'syntax' extension and reference the file from that folder in package.json, but it didn't work. I also tried adding the 'configuration' setting in the 'contributes' section of package.json, without success. I browsed numerous VC Code extensions on GitHub and couldn't find one providing similar functionality.
Is it even possible to provide syntax definition and 'theming' in one extension? If so how?

Based on VS Code Semantic Highlight Guide, besides syntax highlighting rules, you'll also need
Implement and register a Semantic token provider in your extension.
Declare Enablement of semantic highlighting in settings.json.
Customize tokens in Theming.
VS Code team kindly provides a Semantic tokens sample. Note that this example skips step 3 and customizes tokens directly in settings.json.

Related

how to specify what's considered an error, so that I can get squiggly lines

I'm programming in C, and often times I see myself forgetting to type the '&' when using scanf. I've used replit in the past and there, in that case the variable gets a squiggly underline showing it's wrong. Is there any way I could configure this in VS Code, in other words, can I specify what's considered an error?
Add the C/C++ extension from Microsoft. It will add IntelliSense
Use this link to learn how to add extensions: LINK
Use this link to read about customizing IntelliSense for your needs: LINK
(unless it already does what you need)

Disable competing language servers / code highlighters

I want to add a language server to handle completion / highlighting / etc. for a file.
As a basis for testing stuff I am using an example from Microsoft (https://github.com/microsoft/vscode-extension-samples/tree/main/lsp-sample) and changed it to be active for any File. This language server highlights any word in all capital letters.
When opening a C++ File, I get the highlighting / completion of my language server and the default one for C++ (See image).
I would like to detect if some other extension / build in highlighter is active for a file and deactivate it for this workspace or the current file if it is impossible for the current workspace)
Is there a way to do this in a generic way where I do not have to know which extensions are highlighting code?
If no, is there a way to do this, if I know a set of extensions I want to deactivate?
I finally had enough time to try around a bit more and found that providing your own language for the same extension is enough.
In package.json I added an element in contributes.languages with extensions containing .cpp (since I am using cpp files for testing).
I also copied over some implementation code from an example.
This suppressed the default highlighter and code completion for cpp files. Since i am only implementing a semantic token provider, I can see the default highlighting before my provider takes over. (I think this could be solved by adding a syntax highlighter, but this is already sufficient fo my preliminary testing)
I am not sure, how stable all of this would be as a plugin (I only tested in Extension Development Host mode)
Here an image of the results:

How to know which extension provides what snippets in VSCode

I've installed many code snippet extensions in my Visual Stuidio Code, but when I considered to use them, I got several snippets choices with a same input. I cannot tell which one should I use.
Now I have to disable some extensions. How can I find out what extensions that each snippet is provided by? or what snippets an extension is providing?
Select a code snippet, and the extension name is showed in the hint window near the auto completing window.

Visual Studio Code Grammar files location

I'm using Visual Studio Code for development of PHP and would like to style the background color of the different embedded languages HTML/PHP/JavaScript differently, and to trigger the use of heredoc <<<sql .... sql to switch to SQL syntax. From what I can see from VSCode documentation, I need to edit the grammar files stored in storage.json, but for the life of me I cannot find where those files are. Can anyone point me in the right direction?
Sumirizing our comments, in order to modify the extension files, try to access the following folder:
./yourVSCodeFolder/extensions/resources/app/extensions
As you said, for those in windows, that folder is in:
%LocalAppData%\Programs\Microsoft VS Code\resources\app\extensions\php
There you will find a lot of folders that contains JSON files with the instructions of the custom formats and snippets that your editor uses.
For example: in mine, the /syntax/php.tmLanguage.json has all the instructions for how my php should look, and php/language-configuration.json has some parsing rules.
Find the files that allready has the rules that you are looking for, but it could be tricky because maybe you will need a prettyfier and to link or create new rules.
Also, if you didn't, check the Language Extensions Guide that VSCode provides.
Hope it was useful.
PD: As you also said:
VSCode already recognizes embedded SQL as long as the heredoc is in upper case <<<SQL .... SQL

Is there a way to export PhpStorm code style rules as .eslintrc?

I've been using PhpStorm for awhile, for PHP as well as JS. I would love, however, to switch to VSCode since it's lighter, open source and free. But one feature that I cannot quite carry over with extensions is Code Style settings.
PhpStorm has a sweet visual interface in settings that allows you to set up detailed code style rules with live examples right there. ESLint, unfortunately, doesn't have anything similar - it's all text rules (which is a drag and takes forever to set up).
So I'm wondering if there's any way at all to export PhpStorm code style settings as ESLint rules? Or if there's an app that has a similar interface to set up ESLint? Or maybe there's a VScode extension that I am missing that has a similar interface?