microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.52k stars 1.55k forks source link

Need to handle untitled: URI to support Untitled, unsaved files #3343

Open byyxx128 opened 5 years ago

byyxx128 commented 5 years ago

If I open an existed C or CPP file, everything is OK. And the context menu is like this: image

However, if I create a new file and select to C or C++ language mode, the context menu will be like this: image And the formatter doesn't work at this time (even though I press Shift+Alt+F). image

sean-mcmanus commented 5 years ago

It's more than just formatting that isn't working (i.e. no Go to Definition).

Saving the file is the workaround.

I don't see how we could fix this though -- it's looking like a VS Code limitation.

akbyrd commented 4 years ago

There is nothing at the VS Code level stopping code folding from working in unsaved files. This works for C/C++ files in my own extension just fine.

sean-mcmanus commented 4 years ago

@akbyrd Our code checks for the scheme == file and languageId == cpp or c before processing files. I don't know how we would get notified that the languageId changed from "plain text" to c or cpp. Also, we may need to change some of the checks to be "|| scheme == untitled".

akbyrd commented 4 years ago

I'm not experienced with extensions, but I think all I do is register and vscode does the rest. vscode.languages.registerFoldingRangeProvider('cpp', { provideFoldingRanges }); I don't handle any change events for the language.

To verify I disabled the vscode-cpptools folding, enabled mine, opened a new file, pasted some code, set the language to C++ and a few seconds later it updated. It seems to 'just work'.

sean-mcmanus commented 4 years ago

@akbyrd The main issue appears to be in our LSP cpptools process, which isn't written correctly to handle input URIs that are not files. So fixing that seems like it would be a non-trivial amount of work. Changing our documentSelectors and scheme checks in TypeScript is the easy part.