Cannot auto-complete c++ in vs code - autocomplete

Hey I recently started using vs code and am having a really weird issue. where my code won't auto complete. I have installed the c/c++ extension and have the "c_cpp_properties.json" file containning the following
{
"configurations": [
{
"name": "Mac",
"includePath": ["/usr/include"]
},
{
"name": "Linux",
"includePath": ["/usr/include"]
},
{
"name": "Win32",
"includePath": ["c:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include"]
}
]
}
Before you ask I have copied proper include path to "/usr/include" I just did a really simple test I wrote 1 line
"VkInstance instance;"
It compiled and ran fine but whenever I start to type VkInstance It never comes up as auto complete. Moreover weirdly some stuff auto completes fine and other stuff doesn't for example "vkCreateInstance" shows up as i'm typing it. Perhaps I'm missing something or doing something wrong would like some feedback
Thanks!
#include <vulkan/vulkan.h>
int main()
{
VkInstance instance;
return 0;
}

This seems to be a limitation (or bug?) of VSCode's code completion feature. The Vulkan header wraps the typdefs for all handles (like VkInstance, VkFence, etc.) in a Macro and it looks like VSCode can't handle this.
E.g. this:
VK_DEFINE_HANDLE(VkInstance)
Won't autocomplete, but if you replace the macro by hand to get this:
typedef struct VkInstance_T* VkInstance;
Auto-Completion works.
If this is a bug (just had a quick look at this), it may be worth reporting over at https://github.com/Microsoft/vscode-cpptools/issues

Related

How can I get Web API autocomplete/IntelliSense in VSCode?

I'm using VSCode for web development and I noticed that there is no JavaScript autocomplete/IntelliSense for browser-related types such as Element nor functions such as document.querySelector(). Is there an extension for this that anyone has found?
// tsconfig.json
{
"compileOnSave": true,
"compilerOptions": {
"alwaysStrict": true,
"checkJs": true,
"outDir": "./root/js",
"rootDir": "./src",
"target": "ESNext"
},
"exclude": ["./root/**/*"],
"include": ["./src/**/*"]
}
I was starting to type out document.querySelector() and noticed halfway through that autocomplete wasn't triggering. I triggered it manually (Ctrl-I) and got no suggestions.
For clarification, I'm looking for something that will do this, but with frontend code:
Tried searching for extensions in marketplace, on Google, in VSCode itself - to no avail.
The issue is that the lib field (tsconfig.json or jsconfig.json) hasn't been set to include "dom", which tells the TypeScript compiler (and VS Code's TypeScript support) to include types for web APIs like the DOM.
Fun fact: If you leave the lib field empty, TypeScript will assume certain things to be in it "by default". For more info on that, see this answer I wrote to "How can I make vscode assume a node.js context, so that it doesn't assume fetch exists?"
Turns out #user was right — I needed to add this to my tsconfig.json:
{
"lib": [
"DOM"
]
}

VSCode: Add token colour customisations to a syntax highlighter extension

I've been trying to create a test extension for a custom code highlighting.
The extension works perfectly fine but I am wondering how can I attach the token colour definitions, sort of like a default if people don't add it to the settings.json.
At first I thought I could do it in package.json in the contributes section but I can't get it to work.
Here's an example of what I'm trying to "attach" to my extension:
{"scope": ["source.qqql.scope"], "settings": {"foreground": "#aaaaaa"}},
{"scope": ["source.qqql.scope.type"], "settings": {"foreground": "#6997bf"}},
{"scope": ["source.qqql.scope.name"], "settings": {"foreground": "#555555"}},
I also tried adding it to
"configurationDefaults": {
"[qqql]": {
"editor.tokenColorCustomizations": [
"textMateRules": [<here>]
]
}
}
in the package.json but upon testing with F5 it didn't colorise the tokens.
I followed this topic: VS Code - Text formatting in a new language extension but I fear I'm missing a step or a crucial part of understanding how to do it. Any help would be appreciate it.

How do I visually replace an expression in VS Code with a symbol?

I am using Visual Studio Code for Python development.
A very common expression in python is lambda x: x which can be a little verbose when used 40+ times in a module.
Does VS code allow for this to be replaced with a symbol? eg. replacing lambda with λ?
So code like df.apply(lambda x: x**2) would appear as df.apply(λx: x**2)
To clarify, I DONT want to modify the source code, I just want it to be displayed on my code editor using the shorthand.
Very late to the party, but I recommend using this extension: prettify-symbols-mode
Adding following config to settings.json worked for me:
"prettifySymbolsMode.substitutions": [{
"language": "python",
"revealOn": "active-line",
"substitutions": [
{ "ugly": "lambda", "pretty": "λ", "post": "\\s*(?:\\w|_).*?\\s*:" }
]
}]

VsCode - Triggering a snippet upon file creation

I wanted to know if it is possible to trigger a user defined custom snippet when I create a file in vscode.
I started learning Golang recently and noticed that there is some boilerplate code that goes into creating the main.go file.
So I created my custom snippet for it and now now I can trigger the snippet manually and save me some keystrokes of typing.
I wanted to go one step further, so that whenever I create a new file named main.go from within VsCode, it should automatically fire that snippet and insert the biolerplate code for me, without me having to manually trigger the snippet.
Is this even possible ?
Check out this extension: Auto Snippet:
With this in your settings.json:
"autoSnippet.snippets": [
{ "pattern": "**/main.go", "snippet": "main-go-template" },
],
[Note that the example settings in the extension docs has a few syntax errors - use my example above - I have filed an issue with the creator.]
And then your snippet
"main-go-template": {
"prefix": "zz",
"body": [
... // you can use tabstops and transforms just like regular snippets
]
"description": "javascript template"
}
Then creating a new main.go file or opening an empty one should trigger the snippet.
It is a good idea to reload vscode whenever you make a change to this extension's settings.
Here is a demo of a gulpfile with common boilerplate:
Also see this extension https://marketplace.visualstudio.com/items?itemName=bam.vscode-file-templates

Where are the docs on how to add symbol support for a language to Visual Studio Code?

I would like to add symbol support for PowerShell to VS Code but I'm not finding any docs on the code.visualstudio.com/docs site.
Also, is it possible to do this for a language like PowerShell that, for the moment, will only work on Windows? Is there a way to light up symbol support on Windows only?
BTW I've added a bunch of PowerShell snippets that I'm in the process of trying to get integrated into VS Code. Any help on how to get these snippets into the product would be appreciated as well? I did submit an issue on the snippets, suggesting that the team put these into VS Code.
There is currently no documentation for the plugin API. It's too early for this as the API is still changing with every minor release. The VSCode team is focused on providing a stable plugin API. There will be a documentation about it when it's done.
Nevertheless it is already possible to add a new language plugin or extending an exisiting one. Take a look on this short description on how to add declaration support for a new language: Create Custom Language in Visual Studio Code
You could add symbol support in a similar way. What you need is something like an abstract syntax tree builder for powershell scripts and an application or a javascript module that is able to process a JSON request in order to provide the correct symbols. An example request for outline support is this:
{
"seq":442,
"type":"request",
"command":"navbar",
"arguments":
{
"file":"c:/Users/C/Documents/projects/MyProject/MyFile.xxx"
}
}
A response could look like that:
{
"seq":442,
"type":"response",
"command":"navbar",
"request_seq":442,
"success":true,
"body":[
{
"text":"TObjA",
"kind":"class",
"kindModifiers":"",
"spans":[
{
"start":{
"line":10,
"offset":3
},
"end":{
"line":16,
"offset":4
}
}
],
"childItems":[
]
},
{
"text":"DoSomething",
"kind":"method",
"kindModifiers":"",
"spans":[
{
"start":{
"line":20,
"offset":1
},
"end":{
"line":27,
"offset":4
}
}
],
"childItems":[
]
},
]
}
I'm not sure what do you mean with "symbol support". Is it something like "jump to symbol inside the current file" using CTRL+Shift+O? Then you are looking for outlineSupport.
Is it something like "find a symbol in any file" using CTRL+P, #? Then you are looking for navigateTypesSupport.
Copy the needed .js file from the vs.langauage.csharp.o folder to the vs.langauage.powershell folder and register the support in powershellMain.js as it is done in omnisharpMain.js.
If you want to register the new support only on Windows then you can do it like this:
var isWin = /^win/.test(process.platform);
if(isWin)
monaco.Modes.NavigateTypesSupport.register('powershell', new navigateTypesSupport_1.default(ModelService, server));
I hope this helps for the moment. Don't forget to save your changed plugins in a different folder. VSCode often deletes changes in the plugin folders on update.