I find the default intellisense suggestions for Javascript irrelevant. Too many native browser functions I will never use.
Is there any way to turn off/limit intellisense? e.g. hide browser methods like the one in the link above.
To disable the default set of globals, create a jsconfig.json file at the root of your project with the content:
{
"compilerOptions": {
"lib": ["es6"]
}
}
This prevents the TypeScript service that VSCode uses for JavaScript IntelliSense from automatically including information about the DOM api.
You can read about all the avalible lib configuration options in the TypeScript documentation.
Related
I generated a VS Code web extension, registered the language into the package.json file, and put this code snippet into the extension.ts file:
console.log('activation');
context.subscriptions.push(vscode.languages.registerHoverProvider(selector, {
provideHover: function (document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): vscode.ProviderResult<vscode.Hover> {
console.log('hover');
return new vscode.Hover('test');
}
}));
If I start the extension by pressing the F5 key (it starts a new VS Code instance to run the extension), it works fine, but if I run the run-in-browser npm script it doesn't work. The activate function runs in both cases, because I see the text 'activation' in the console, but if I run in the browser I can't see the text 'hover'.
In normal (not web) VS Code extensions I can use both the VS Code API and the Language Server Protocol to implement language features like hover, formatting, go to definition etc. In the web extensions page they don't mention that I can only use the Language Server Protocol (and not the API) in web extensions, but in the only web extension sample where they implement language features, they use the Language Server Protocol.
So, is it possible to use the VS Code API to implement language features in web extensions, or I have to use the Language Server Protocol? If it's possible, why my code doesn't work in the browser but it does in desktop VS Code (using the web environment)?
I was asking myself recently if it is possible to add snippets to either one of the workspace, language-specific or global json snippet files through a VSCode extension.
// something like
Command.addSnippet('''
{
"prefix": "my_snippt",
.... etc.
}
''')
Reading through the API documentation I did not find anything. If there is no way, how would you go about creating kind of a snippet manager?
You can use SnippetString and a CompletionItemProvider to dynamically suggest snippets.
Here is an example.
I am developing my first firefox extension on vscode and just discovered that autocomplete/intellisense isn't working for web extension APIs e.g. browser.tab, browser.extension like it does for regular JavaScript. I like the intellisense feature because it minimizes errors and docs consultation. A google search result suggested I add:
{
"typeAcquisition": {
"include": ["firefox"]
}
}
in a jsconfig.json file which I've done but the issue still persists. Is there a way I can get intellisense to work here or am I out of luck?
Create a jsconfig.json file in your source and add this line to it ⤵︎
{"typeAcquisition": {"include": ["firefox-webext-browser"]}}
You should then have suggestions for the browser namespace.
Can I get the list of the available scopes for snippets?
Is there any native functionality that would control what files to create and where?
Snippets are scoped to languages and introduced to VS Code as global or local to a workspace. Languages can be contributed to VS Code by exceptions. Typically by declaring a language in the package.json, adding a syntax and snippet files. Update:
Here is the guide how to add a snippet to any language via your extension. If you follow the guide and add a snippet to the current workspace, you will notice that the file with extension .code-snippets gets created under the .vscode folder in the workspace. Therefore you can enumerate all such files using the vscode.workspace.workspaceFolders and fs.readDir APIs.
vscode.workspace.workspaceFolders!.forEach(workspaceFolder => {
const snippetFiles = fs.readdirSync(path.join(workspaceFolder.uri.fsPath, '.vscode'))
.filter(el => /\.code-snippets$/.test(el));
});
Similarly, the global snippets get added as .code-snippets files into the user profile folder - on Windows it looks like this: C:\Users\currentUser\AppData\Roaming\Code\User\snippets\*.code-snippets. Both locations you can scan for *.code-snippets files as well as programmatically add such files to those folders.
Here is the documentation how to add snippets to a scope via a file. There does not seem to be any public API to enumerate all such snippet files in a programmatic way.
But if you want to retrieve list of the languages in the screenshot you posted, use this API:
vscode.languages.getLanguages()
It could help if you explained what are you trying to achieve. Do you want to find where a particular snippet is coming from to change it? Do you want to add a snippet to a language in this list? Or to a language that is not on this list?
Good day,
In above picture, stylelint prompt a CSS error in a JS file. Is there a way to stop stylelint from validating javascript file, I coundn't find such option in their official configuration guide.
Thanks a lot.
The linter can be configured to ignore specific files using the ignoreFiles property of the stylelint configuration object.
You can try ignoring JavaScript files with:
{
"ignoreFiles": ["**/*.js"],
"rules": { .. }
}
I believe the stylelint Visual Studio Code extension will respect this property.
Look at this part in the documentation.
You can specify /* stylelint-disable */ at the top of a file to disable the whole file from being lint.
Or, better, juste specify /* stylelint-disable-line */ to disable for a single line.
stylelint:validate
You can stop style-lint from VScode to ignore the javascript file too.
In settings search for stylelint -> at the bottom you can see Stylelint:Validate part. Select javascript and delete. It should fix your problem