Share Visual Studio Code editor settings for alternate file extensions - visual-studio-code

How can I configure VS Code settings so that the editor for an alternate file type (different file extension) that contains text in the format of a well-known existing editor type can reuse/share the existing editor and editor settings?
A couple of editors where this might be common are custom file extensions that might contain YAML, JSON, or XML. I have alternative file extensions with this content but want to use the existing editor and settings.
One example is essentially telling VS Code that a RAML file should be edited as YAML. There are many examples for each of YAML, JSON, and XML where this would be useful.
p.s. I know that if there is an editor extension available for a specific file extension, this would not be necessary. This is for the case where either there is no editor extension or the extension does not provide editor customization (tabs, etc.)

Related

XML file validation in Eclipse RCP application for different customized/different file extensions

I have some customized (different file extensions than the conventional .xml files) XML files on my Eclipse RCP application and I need Eclipse to display error markers like it does for .xml files when the format is incorrect (for example if there's no end tag for the beginning tag or if the angle brackets are missing). I can easily set this up manually in Preferences -> Validation -> XML Validator -> Settings -> Add new File Extension Rule for my custom file extensions and after setting up this preference the error markers correctly display for my custom XML files when the format is incorrect but I would like this behavior to apply even though the preferences are not set for different file extensions (something we could setup using .ini file).
When I set the File Extension Rule for my custom file extensions then Eclipse stores this following preference in org.eclipse.wst.validation.prefs node -
vals/org.eclipse.wst.xml.core.xml/groups=0107include07111contentType128org.eclipse.core.runtime.xmlT111contentType134org.eclipse.wst.xml.core.xmlsourceT111contentType134org.eclipse.wst.xml.core.xslsourceT111contentType134org.eclipse.jst.jsp.core.tldsourceT07fileext03xmlF07fileext06varselF07fileext06vardefF0107exclude05113projectNature134org.eclipse.jst.j2ee.ejb.EJBNature113projectNature130org.eclipse.jst.j2ee.EARNature04file08.projectT0104file110.classpathT0104file110.settings/T02
And I tried adding the same entry to my product's .ini file and expected the settings to be read upon the product start and the validation behavior to be applied on my Eclipse RCP product to my custom file extension XML files without explicitly setting the preferences manually.
I looked upon the internet for solutions but got nowhere close, what am I doing wrong here? Are the entries I added to my .ini file correct? How can I enable validation for my custom file extension XML files (XML files with different file extensions)?
A better solution would be to add filename extensions to the relevant Content Type, via an "extension" element in your own plugin.xml file. Then almost every feature meant for XML files will, or should, apply to your own--validators, editors, task tag scanning, etc. The Platform defines one content type for XML files, and the WTP XML plug-ins define another specifically for files that could be considered ill-formed or syntactically broken, the ones that would be unreadable by most production XML parsers. They are org.eclipse.core.runtime.xml and org.eclipse.wst.xml.core.xmlsource, respectively. The Validation framework will then automatically consider your files as candidates for the XML Validator.
https://help.eclipse.org/latest/topic/org.eclipse.platform.doc.isv/reference/extension-points/org_eclipse_core_contenttype_contentTypes.html?cp=2_1_1_9

What is the best way to access the VS Code intellisense settings via the API?

I'm building an extension that needs to harvest some of the intellisense settings from the c_cpp_properties.json file, specifically the values for "includePath" and "defines", and I have some questions.
Does VS Code support file specific intellisense settings? For example, if I want to set -DBOZO for foo.cpp and -DBINGO for bar.cpp.
Does the API have a way to access the intellisense settings, or should I just parse the json file myself (which is simple)?
If I need to parse the json file, then for a multi-root workspace, what is the best way to find the .vscode folder for a particular file? I know I can use the variable ${fileWorkspaceFolder} in tasks.json for example. Is there programmatic access to variables like this from the API?
Thanks!

VSCode: Can I enable an extension by file extension?

I would like to enable a VSCode extension only for certain file types.
Specifically, I'd like to enable spell check only in markdown files and other text documents.
Enabling spellcheck by workspace doesn't meet my intent. I often want spellcheck in workspaces that have both markdown and other code files.
Potential lead:
I know languages activation events can be specified in an extension manifest. It doesn't appear that I can customize that manifest without creating a new plugin though.

Associate file type to my vscode extension like a project file

I'd like to do something like a project file. When the user opens it, the webview of my extension would welcome the user instead of the default VSCode editor.
I know I can workaround it by adding extra context menu items or buttons, but in this case I'm curious if it's possible to override that it by default tries to open in the editor.
Is this possible either manually or automatically?
What you're after sounds exactly like what the upcoming webview / custom editor API hopes to accomplish.
The custom editor API aims to allow extensions to create fully customizable read/write editors that are used in place of VS Code's standard text editor for specific resources. These editors will be based on webviews. We will support editors for both binary and text resources.
See the following issue for more info and further links to the proposed API, example extensions etc:
Custom webview editor API (#77131)
Note that it usually takes a while for new APIs to make it into stable releases after being made available as "proposed APIs".

How to associate a custom file extension with the MSBuild Tools in VSCode

Take any C# project file (*.csproj and rename it to *.build and then open it with VS Code. It will be recognized as XML.
What I would like is to associate VsCode MSBuild Tools with that custom extension. I already tried provide a file association like
"files.associations": {
"*.build":"csproj"
}
files.associations changes the language type, so the example you gave tells vscode that *.build has the language id csproj. There is no language id csproj by default and this extension does not add one. What you really wanted was this:
"files.associations": {
"*.build":"xml"
}
That tells vscode to treate .build files as xml files.
However, that still won't fix your problem. I looked at the code in the extension by installing it and digging around (unfortunately it isn't on github) and I can see that it explicitly checks for files that match one of the following:
RegExp("\\.props$"),
RegExp("\\.targets$"),
RegExp("\\..*proj$")
.build does not match that and therefore the extension will not work on those files.
I suggest leaving a review on the marketplace asking for two things:
1) the extension source to be put on github
2) the author to make the extensions parsed configurable in user settings
You may also consider alternative extensions such as this one.