How can I make my VS Code extension provide suggestions and syntax-highlighting for non-JS code in ES6 tagged template literal strings? - visual-studio-code

I’m working on a GraphQL extension for Visual Studio Code that implements syntax highlighting and auto-completion for GraphQL schemas and queries. It currently works on files ending with the .gql extension. However, a common GraphQL usage is to define inline queries inside JavaScript/TypeScript files, for instance:
#connect(gql`user(id: 2) { name, email }`)
function MyUIComponent({ user }) { ... }
How could I support the highlighting and suggestion (autocompletion) features that my extension implements in ES6 (named) tagged template literal strings?

As linked in the comments under the question post, this is related to this github issue: Extension providing language support in ES6 template strings #5961, which was resolved by this comment by one of the maintainers, Matt Bierner:
VS Code Extensions can now bundle ts server plugins. This allows extension authors to write a vscode extension that adds syntax highlighting + intellisense for template strings.
Two extensions are already making use of this: [...]
I did a quick google of graphql ts server plugin and found this: https://www.npmjs.com/package/ts-graphql-plugin.
Quoting from its readme's "getting started" section:
First, confirm that your project has TypeScript and graphql(v15.x.0 or later).
To install this plugin, execute the following:
npm install ts-graphql-plugin -D
And configure plugins section in your tsconfig.json, for example:
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"plugins": [
{
"name": "ts-graphql-plugin",
"schema": "path-or-url-to-your-schema.graphql",
"tag": "gql"
}
]
}
}
It's ready to go. Launch your TypeScript IDE.
So to answer your question of "How could I support the highlighting and autocompletion features that my extension implements in ES6 (named) template string?", either you don't need to (just tell your users to include that TypeScript Server plugin), or you can find some way to integrate that into your plugin.
You could also try to take inspiration from the approach used by the Template Literal Editor extension.
Quoting from its readme:
Open ES6 template literals and other configurable multi-line strings or heredocs in any language in a synced editor, with language support (HTML, CSS, SQL, shell, markdown etc).
Instructions: [...]
Other related tools:
This won't add suggestions, but for syntax highlighting in tagged template literal strings, there is the comment-tagged-templates extension by Matt Bierner.

Related

Rule for obsolete CSS properties?

I'm looking for a Stylelint (and/or ESLint) plugin/rule that has a rule for avoiding the usage of obsolete CSS properties like grid-row-gap.
I'd like to believe someone already made this, but I couldn't find anything like it via Google, GitHub, or npm.
A plugin that also does the same for [warning] when using experimental properties/selectors would also be welcomed (e.g. :focus-visible).
Recently I started to develop a collection of rules in this plugin.
npm install #isnotdefined/stylelint-plugin
Refer the plugins and rules inside your .stylelintrc file:
{
"plugins":
[
"#isnotdefined/stylelint-plugin"
],
"rules":
{
"#isnotdefined/no-obsolete": true
}
}
At this point I need assistence to find more obsolete properties and values. Just in case someone knows a public list - let me know.

I want to use the Babel plug-in: optional-chaining, but the vscode console prompted me incorrectly. How can I solve this problem?

I created a new project with the create-react-app scaffold, and then I wanted to use the optional-chaining plug-in of babel. I installed the package according to the document and configured it, but vscode prompted grammatical errors. What can help me? please.
this is my package.json.
this is the problem:
If you are using CRA there is probably no way instead of ejecting project and applying Babel presets manually (according to https://github.com/facebook/create-react-app/issues/4604).
However, if you are decided to use eject there should be able to add plugin to babel config which is described here https://babeljs.io/docs/en/babel-plugin-proposal-optional-chaining. Probably applying stage-0 preset of Babel (https://babeljs.io/docs/en/babel-preset-stage-0) can also be a solution.
Edit: see also Null-safe property access (and conditional assignment) in ES6/2015
The error you are seeing is from Visual Studio Code's built-in JavaScript and/or TypeScript validator. In order to circumvent this, add this to your vscode settings.json file:
"javascript.validate.enable": false
Additionally you can disable the built-in TypeScript validator like this:
"typescript.validate.enable": false
Once those are disabled, eslint will take over and show you the proper errors when applicable.

develop and debug multiple VSCode extensions at once

I am currently developing some custom VSCode extensions and would like to have separate optional extensions that build on a core extension. Currently it is a bit of a hassle to develop these congruently and I am currently aware of the following options:
1) Develop the extensions separately with separate debug instances
The downside here is that until the extensions is published or moved to your ~/.vscode/extensions folder the two extensions have no knowledge of the development versions of each other, making the debugging and rapid additions quite difficult.
2) Move extensions into ~/.vscode/extensions folder
The downside with this is that there is constant window reloading, sometimes it can be tricky to know when the main process has fully loaded the updated version and it has definitely been less convenient than the experience when developing one extension
3) Merge the two extensions into one extension
This makes debugging and rapid feature builds easier, but goes against some of the original modularization i was hoping for, so i haven't switch to this as of yet.
My question is, is there a better way people have found to accomplish this apart from the above 3 options i'm aware of? I've combed quite a bit through google, forums, and the vscode docs looking for options or other people hitting the same situation but haven't found anything as of yet.
From the VSCode docs, it appears that --extensionDevelopmentPath "might" support multiple paths somehow, but i have yet to find anything conclusive or with examples of that to get it to work.
One method that I have used is to pull in the 'core' extension in as a submodule into a subdirectory, for example, .dependencies. Remember to npm install the 'core' extension from within its directory.
Then I would adjust your package.json on the working extension to use the following scripts:
"scripts": {
...truncated for brevity...
"compile:core": "tsc -p .dependencies/{dep-folder}"
"compile:me": "tsc -p ./"
"compile": "npm run compile:core && npm run compile:me"
...truncated for brevity...
}
Finally, add the following to your launch.json which will override VSCode's default extension folder to your .dependencies folder.
"args": [
"--extensions-dir=${workspaceFolder}/.dependencies"
"--extensionDevelopmentPath=${workspaceFolder}"
]

"List All References" not available in context menu in VSC 1.29.1

I recently upgraded to VS Code 1.29.1 on my Ubuntu virtual machine and was very excited to try out the new List all References preview, but I can't seem to invoke it anywhere. It isn't in the context menu, and trying View: Show Reference Search through the Command Palette does nothing.
Image: No "List All References" option in the context menu when highlighting a function name.
Why does the option not appear, and is there anything I can do to enable it?
My working context:
I'm working on Ubuntu 14.01 LTS and this is for a C project; all of the files in the workspace are *.c, *.h, Makefiles, and perl scripts. I have Intellisense for C/C++ enabled with the ms-vscode.cpptools extension. The only other Marketplace extensions I have installed are color/icon theme-related. Symbol searching, go/peek to declaration/definition, quick info, error squiggles, etc. are all working properly.
Things I've tried:
verified that I'm actually using version 1.29.1 via the Help>About menu option (and confirmed multiline regex searching works)
skimmed the GitHub repo for both open and closed issues and didn't find any similar issues
searched the docs and patch notes
tried various .c and .h files within the workspace.
I'm not familiar enough with the extension and language provider architecture to know where to go from here, and I couldn't glean any caveats from the docs about the new List All References feature, so any help is appreciated.
The List All References feature is based on Find All References, which is supposed to be implemented by the language provider. In my case, the ms-vscode.cpptools language provider has not implemented Find All References, so the List All References feature is unavailable.
(I realized the one thing I hadn't checked were the issues in vscode-cpptools.)
Relevant issue: https://github.com/Microsoft/vscode-cpptools/issues/15#issuecomment-438905148
I guess as a PSA, if you're on VSC1.29.1 and don't have the List All References option, look to your language provider.

How can I configure autocomplete for project in Brackets?

I'm using Brackets for development applications on the Node.JS. As I know Brackets relies on the TernJS library. When I add the root of the project file named .tern-project with the following lines, I do not see any change in the autocomplete.
{
"libs": [],
"plugins": {
"node": {}
}
}
After that I still see hints for browser, JQuery hints, AngularJS hints, etc. How can I configure TernJS for project(directory) in Brackets?
I've found the ternific plugin to work pretty well for per project tern configuration.