LSP icon indicating copy to clipboard operation
LSP copied to clipboard

Implement workspace/didCreateFiles

Open ayoub-benali opened this issue 4 years ago • 12 comments

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 ?

ayoub-benali avatar Jun 10 '21 14:06 ayoub-benali

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?

rwols avatar Jun 10 '21 20:06 rwols

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.

rchl avatar Jun 10 '21 21:06 rchl

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?

rwols avatar Jun 10 '21 21:06 rwols

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.

rchl avatar Jun 10 '21 21:06 rchl

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

rwols avatar Jun 10 '21 22:06 rwols

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

rchl avatar Jun 10 '21 22:06 rchl

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 ?

ayoub-benali avatar Jun 11 '21 11:06 ayoub-benali

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

rchl avatar Jun 11 '21 12:06 rchl

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

ayoub-benali avatar Jun 11 '21 12:06 ayoub-benali

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

rwols avatar Jun 11 '21 19:06 rwols

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

ayoub-benali avatar Jun 15 '21 07:06 ayoub-benali

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

  • The plugin_host has the os module
  • Any plugin can therefore create any kind of file, which may or may not be considered "in-editor". e.g. SideBarTools, SideBarEnhancements, AdvancedNewFile, etc
  • SublimeText picks up these new files with a file watcher, but how would it know whether a file was created in-editor vs via an external command?
  • Therefore, to make workspace/didCreateFiles (and workspace/willCreateFiles) work, the os module should be removed. All file/OS operations should go through the sublime module so that ST can decide if something is in-editor or not.
  • Because of backwards-compatibility I don't see this happening soon.

rwols avatar Jun 30 '21 21:06 rwols