Vscode-cpptools: autoconvert '.' to '->' when the type is a pointer

Created on 3 Jul 2017  路  24Comments  路  Source: microsoft/vscode-cpptools

First off, the new intelliSense engine is awesome! Exactly what we've been waiting for. Thanks for taking our feedback and making that happen.

It seems to me that when the "Default" engine is enabled and doesn't need to fallback to the tag parser, you have enough type information to separate pointer objects from non pointer objects. It would be really nice in those cases to convert '.' to '->' if the object type is a pointer (or vice versa).

Feature Request Language Service Works in VS fixed (release pending)

Most helpful comment

The fix is available with 0.29.0.

All 24 comments

Yeah, VS 2017 implements this for raw pointers (smart pointer classes have a valid . operator so it gives results for the point itself and not the object that is pointed to).

@sean-mcmanus Is this feature added to the VSCode?

We haven't added it to VS Code yet.

Is this feature added to the Cpptool?

@ranqiyu It's not added yet. We're working on other features. It has not been scheduled.

Is there somewhere I can vote to have it scheduled?

The thumbs up on the initial post.

Gotcha. I would like to add that if/when this does get implemented, there needs to be a way to disable it for a specific language, because in Objective-C, dot syntax is used for property access on Objective-C objects. Or, if it can intelligently switch between ./-> on the fly鈥攕ay when choosing an ivar without a similarly named property from the autocompletion list鈥攖hat would work instead.

Our extension doesn't support Objective-C. As long the as the language of the doc is not C or C++ then Objective-C shouldn't be affected.

I' d like a config to also complete -> for smart pointers since they are used more often. Don' t know if it is possible when we press backspace on autocompleted -> it would become .

The fix is available with 0.29.0.

Hello folks. I love the fact that it has been fixed. Thanks!
I have 0.29.0. But I can't find how to enable the auto dereferencement.

@sean-mcmanus I have a simple question about how this was implemented.

Some background: I suggested this feature to the PHP intellisense developer鈥攖he exact same way you guys made it work鈥攂ut he said it should be a "client-side" feature implemented by another extension and not the language server.

My question is this: does the LSP provide an API for modifying text behind the cursor when an autocomplete suggestion is selected, the way this feature works? And if not, how did you guys implement this?

LSP Relevant section: https://microsoft.github.io/language-server-protocol/specification#textDocument_completion

The CompletionItem object has a property called "additionalTextEdits" that lets you make changes to the document behind the cursor. We replace the . with a - using the "additionalTextEdits" and put the > preceding the name of the member.

@tionebrr, feel free to open a new issue with details about what you are trying and what you expect to see.

Thanks so much! Just what I was looking for.

Is there any way to do the convert on smart pointers?

@yxkemiya Potentially, but smart pointers have their own valid methods accessible using ".", so if sp.get() is valid then we wouldn't want to change it to sp->get(). The features request would need to be made to Visual Studio itself probably first though, since they don't implement that behavior yet.

I'm trying to use this in 0.29.0, but apparently . gets converted to -> only if I use auto-complete suggestions. It doesn't work if I just type entirely the member name, which actually happens often. Is there a way for the conversion to happen right when typed, like QtCreator does?

@Zylann I don't understand. Could you provide more details on what you expect? If there are no auto-complete suggestions shown, then that would imply IntelliSense isn't working and we wouldn't be able to tell if the member name is a pointer type or not.

@sean-mcmanus what I originally asked in the issue closed in favor of this one, is that when I type . after a pointer variable (something Intellisense knows), to be converted to ->. It wasn't really related to the dropdown, but currently this is only happening when I use an item from the drop down after I start to type, it is not happening otherwise. The drop down does show, but I don't get an arrow if I don't pick an item. This is frequent because sometimes, typing is faster than using the dropdown (or I just decide to not use it for some reason, it happens), and it may not necessarily have the entry I want (Intellisense is slow at times).

Whereas in QtCreator, if I type engine., this happens right off the bat:
image
Which also is more correct in the train of reading than having an invalid . being corrected only later (at first I even thought it wasnt working at all).

Unfortunately, I don't think that is possible for us to do with the current VS Code extension APIs, see https://microsoft.github.io/language-server-protocol/specification#textDocument_completion . We send VS Code a list of CompletionItems, but the edits for changing . to -> are per-CompletionItem and there isn't any API for telling VS Code that we want the textEdit to always be applied even when no completion is selected. I think you would need to file a feature request at https://github.com/microsoft/vscode/issues . We could possible popup a Code Action on the "." with the edit action associated with it, i.e. a Quick Fix.

@Zylann you're not using autocomplete if you type the suggestion out yourself. Why would you expect it to change it for you if you're not triggering the suggestion?

@NSExceptional because it's still useful. I explained why. If you identify the dropdown as "the autocomplete", then my request isnt even about it, it's about typing . after a pointer type (though you could consider doing it only if the said pointer has members ofc).

Was this page helpful?
0 / 5 - 0 ratings