-
-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue Tracker: Replace altercommand #1260
Comments
@justinmk some early questions. I understand how However, what about commands like Is there a |
Additionally, what about |
Same question with Edit: I guess in this situation I could compare the current filename vs |
@justinmk bump. It looks like |
In neovim, I tried collecting as much information as possible. However, this is the data I get on a maybe I can try to figure out the position of the new window and calculate the most likely split, but that seems like a lot of work. However, a window position sync api does seem like it could work well with some nvim plugins. |
There is I see the window layout stuff as a lower priority. Mappings are the right approach there, for now. The main priority imo is to remove complicated layers of hacks except where absolutely necessary.
|
Thanks for the advice! Yeah I was hoping that this effort could entirely remove altercommand but I guess only partially for now. Regarding letting nvim open the file, I think it's not possible given the reasons Alexey mentioned. That's because not all files are on the local filesystem (wsl, remote workspaces, liveshare, etc). |
For those cases IOW:
|
Sounds good, hopefully I will have time to look into this before the summer runs out. FWIW, this will also enable improvements with shada/undo history. |
@xiyaowong this might be a good PR for v1.0.0 as well, if you are interested. Removing as many (probably not all) altercommands as possible will remove a lot of hacks. |
Removing altercommands for |
Moving some discussion from here #2027 (review) I was doing some investigating today, and this got a bit thornier. In response to @theol0403's roadblocks
I think we already do this here vscode-neovim/src/buffer_manager.ts Lines 613 to 614 in 350a35c
The only challenge is changing that URI when it changes (e.g. after a "save as"), but I think we could do that with
Quite easily, actually. We can modify the above to be something like this: diff --git a/src/buffer_manager.ts b/src/buffer_manager.ts
index 0ad931b..6023385 100644
--- a/src/buffer_manager.ts
+++ b/src/buffer_manager.ts
@@ -588,18 +588,11 @@ export class BufferManager implements Disposable {
*/
private async initBufferForDocument(document: TextDocument, buffer: Buffer, editor?: TextEditor): Promise<void> {
const bufId = buffer.id;
- const { uri: docUri } = document;
- logger.log(docUri, LogLevel.Debug, `Init buffer for ${bufId}, doc: ${docUri}`);
+ logger.log(document.uri, LogLevel.Debug, `Init buffer for ${bufId}, doc: ${document.uri}`);
const eol = document.eol === EndOfLine.LF ? "\n" : "\r\n";
const lines = document.getText().split(eol);
- // We don't care about the name of the buffer if it's not a file
- const bufname =
- docUri.scheme === "file"
- ? config.useWsl
- ? await actions.lua("wslpath", docUri.fsPath)
- : docUri.fsPath
- : docUri.toString();
+ const bufname = await this.bufnameForTextDocument(document);
await this.client.lua(
`
@@ -612,18 +605,21 @@ export class BufferManager implements Disposable {
vim.api.nvim_buf_set_var(bufId, "vscode_editor_options", vscode_editor_options)
vim.api.nvim_buf_set_var(bufId, "vscode_uri", docUri)
vim.api.nvim_buf_set_var(bufId, "vscode_uri_data", docUriJson)
- vim.api.nvim_buf_set_name(bufId, bufname)
vim.api.nvim_buf_set_option(bufId, "modifiable", not isExternalDoc)
- -- force nofile, just in case if the buffer was created externally
- vim.api.nvim_buf_set_option(bufId, "buftype", "nofile")
+ -- force acwrite, which is similar to nofile, but will only be written via the BufWriteCmd autocommand.
+ vim.api.nvim_buf_set_option(bufId, "buftype", "acwrite")
vim.api.nvim_buf_set_option(bufId, "buflisted", true)
+
+ if bufname ~= vim.NIL then
+ vim.api.nvim_buf_set_name(bufId, bufname)
+ end
`,
[
bufId,
lines,
makeEditorOptionsVariable(editor?.options),
- docUri.toString(),
- docUri.toJSON(),
+ document.uri.toString(),
+ document.uri.toJSON(),
bufname,
this.isExternalTextDocument(document),
],
@@ -638,6 +634,18 @@ export class BufferManager implements Disposable {
actions.fireNvimEvent("document_buffer_init", bufId);
}
+ private async bufnameForTextDocument(doc: TextDocument): Promise<string | undefined> {
+ if (doc.isUntitled) {
+ return undefined;
+ } else if (doc.uri.scheme === "file" && config.useWsl) {
+ return await actions.lua("wslpath", doc.uri.fsPath);
+ } else if (doc.uri.scheme === "file") {
+ return doc.uri.fsPath;
+ } else {
+ // We don't care about the name of the buffer if it's not a file
+ return doc.uri.toString();
+ }
+ }
/**
* Create new neovim window
*/ By not giving the buffer a name, we allow nvim to handle unsaved buffers for us (e.g. it won't send a
Yes, probably.
I think this, above all else, is the hard problem, for a couple of reasons.
Maybe there's an easy answer to the above that I'm not seeing, but I do think we are limited by VSCode a bit. |
This comment was marked as outdated.
This comment was marked as outdated.
If you open a new file (just hit ctrl+n), and then run
I suppose one thing we could do is throw an error on write if given an absolute path with no open folder...? Not amazing but not awful.
This is an interesting approach, but I'm not sure that I understand what benefit the tab-local CWD gives us. If we already have a workspace, I think we have a pretty easy default of just joining the file name to the workspace root already, right? |
Got it. There is a way to pre-fill the directory + filename in the "save as" dialog, so the worse case is simply that the user hits "OK". Seems acceptable to me.
If you open an untitled file in vscode without choosing a folder/workspace then you can't really have any other expectation 😄 (seriously though). |
Do you know how to do that off hand? The only thing I see is
Haha, I'd rather an error than it go waves hands somewhere but I hear you. Minor point, though :) The untitled files is the big one |
What if you constructed a new uri to pass to saveAs? It's not some random ID but instead a structured definition of some resource. |
I did try this with |
https://code.visualstudio.com/api/references/vscode-api#SaveDialogOptions |
Humm. Worth noting it doesn't currently work either so this wouldn't be a step backwards. Maybe we just call the dialogue when bang or a different path to the current URI is passed. |
Nice spot @justinmk! This does exactly what you'd expect. const filenameURI = Uri.file(filename);
window.showSaveDialog({
defaultUri: filenameURI,
}); EDIT: jk, It almost does what you expect. It opens the dialog, but that's it. The save action does nothing. Lame. |
This might be what we need:
|
Saving in this way won't trigger any actions executed by VS Code upon saving. |
Yeah, it also probably won't work with anything other than the most basic cases (e.g. remote dev won't work). I'm gonna poke at this a bit and try to get a first-pass PR up soon |
https://code.visualstudio.com/api/references/vscode-api#FileSystem vscode.workspace.fs can interact with remote filesystems. The best approach is likely only to use it when renaming/saveas, then using the regular save commands otherwise. |
The altercommand hack is very gross. There is some useful information in #887 that should help with removing it.
The text was updated successfully, but these errors were encountered: