Open byyxx128 opened 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.
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.
@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".
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'.
@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.
If I open an existed C or CPP file, everything is OK. And the context menu is like this:
However, if I create a new file and select to C or C++ language mode, the context menu will be like this: And the formatter doesn't work at this time (even though I press Shift+Alt+F).