sublimelsp / LSP

Client implementation of the Language Server Protocol for Sublime Text
https://lsp.sublimetext.io/
MIT License
1.63k stars 181 forks source link

Implement workspace/didCreateFiles #1738

Open ayoub-benali opened 3 years ago

ayoub-benali commented 3 years ago

Is your feature request related to a problem? Please describe. Since LSP 3.17 there DidCreateFiles Notification which allows servers to take action. From example Metals would add the correct package at the top of the file.

Describe the solution you'd like Looking thought sublime API it seems that this can be added via EventListener.on_new(), does it make sense ?

rwols commented 3 years ago

Looking thought sublime API it seems that this can be added via EventListener.on_new(), does it make sense ?

Does this trigger on newly created files, or on any newly created buffers?

rchl commented 3 years ago

on_new() just notifies about opening a new buffer and such buffer doesn't have file path associated yet.

The DidCreateFiles registration would normally define file pattern that should be included so at the point of creating an empty buffer we wouldn't be able to notify yet. But possibly we could set a flag that that view was just crated and notify when that buffer is saved.

rwols commented 3 years ago

We could use on_pre_save and on_post_save together to deduce whether it was a raw buffer previously, and a file-backed view after the save perhaps?

rchl commented 3 years ago

If the info is there then sounds like it could work. Though I feel at the point of on_pre_save the path might be set already.

rwols commented 3 years ago

It also won’t work for files created with the “new file” context menu entry in the sidebar I think.

rchl commented 3 years ago

Right, for those the file watcher would probably be needed.

ayoub-benali commented 3 years ago

Just realized that LSP-metals has a "new scala file" command which could send the notification once completed without relying on Sublime API. Do other LSP packages have such a command ?

rchl commented 3 years ago

that wouldn't cover all cases but would be an option, I guess

ayoub-benali commented 3 years ago

Yeah I agree, a build in file watcher in LSP would be the best solution.

rwols commented 3 years ago

If the file was created via a plugin, is that considered to be “in-editor”?

ayoub-benali commented 3 years ago

For me yes, the plugin is still running in the context of the editor.

rwols commented 3 years ago

I think we're very far away from workspace/didCreateFiles, let alone workspace/willCreateFiles.