vscode-tmlanguage icon indicating copy to clipboard operation
vscode-tmlanguage copied to clipboard

Converter function does nothing when destination already exists

Open gwicksted opened this issue 8 years ago • 8 comments

Similar to #3, no indication is given. At the very least, it should prompt to overwrite the file on disk.

However, it would be nice if it would act almost identically to how it does when no file exists by overwriting the contents of the file in-memory without saving and displaying that file in a new tab (or focus the existing tab if already open). ST3 had a plugin that had this behavior; was very useful.

gwicksted avatar Feb 10 '17 21:02 gwicksted

So it would open a new unsaved tab that would override the existing file when saved? VSCode should prompt the user before overwriting. I'll look at including this in the next release.

Togusa09 avatar Feb 16 '17 11:02 Togusa09

That's perfect! Thank you

gwicksted avatar Feb 16 '17 15:02 gwicksted

Just pinging this issue to also say that this is also annoying me as well. It's a big pain to have to keep deleting and re-adding the .tmLanguage file all the time! 😄

brendanzab avatar Aug 24 '17 10:08 brendanzab

I've just published a release to the store that will generate a unique file name for the new file if one is already found. I realize it's not exactly what I'd described above, but I'll look at adding that as an option as well.

Togusa09 avatar Aug 24 '17 21:08 Togusa09

Yeah, I'd definitely prefer it if one could overwrite the existing file.

I'm also wondering how we could make the development experience easier. I'd like to, for example, regenerate the syntax file as a prelaunchTask when debugging my extension.

brendanzab avatar Aug 24 '17 23:08 brendanzab

@Togusa09 I've got this working where it seamlessly overwrites the existing file (but doesn't automatically save it). The TLDR is: it just needs to use a file:/// prefix if the file already exists vs an untitled: prefix. And select the whole contents and replace it vs inserting the text. I also save/restore the current caret location.

My changes were a bit more involved (full ES6 + strict tslint) so a PR might not be the best way to merge. Here is a gist of my extension.ts file: https://gist.github.com/gwicksted/c49e0420ce40d85d4c86e8dc99e4279c

Feel free to copy/replace as much as you want. Or I can file a PR if you wish. My local copy also has updated packages (via yarn), a tslint.json, the official yaml/json configuration files, added some error handling/reporting, and fixed the readme.md headers.

gwicksted avatar Aug 25 '17 00:08 gwicksted

@gwicksted @brendanzab I've finally gotten around to pushing the changes to make overwriting the default behavior. I mostly borrowed the changes from @gwicksted's gist, but added in a setting for to switch between create/overwrite, but it defaults to overwrite as that's what people want.

@gwicksted If you still have that branch, I'd like to see it; either as a fork or a pull request. TypeScript isn't a language I use often, so it's interesting to see how someone else would have done it.

Togusa09 avatar Oct 08 '17 10:10 Togusa09

@Togusa09 I'm normally not that explicit with the types (if they can be inferred by usage, I won't usually supply them) but that was my first dabbling in VSCode extensions so I made them required in tslint.

Also, I would have used the async and await pattern instead of raw promises but was not sure at the time if it was supported in VSCode (I believe it is). This would reduce nesting except the ifExists function which has to use promises due to node's callback API.

I'll try to get it as a fork on GH. Not many changes other than that one file.

gwicksted avatar Oct 10 '17 18:10 gwicksted