LaTeX-Utilities icon indicating copy to clipboard operation
LaTeX-Utilities copied to clipboard

Edit Live Snippets File does not work on UNIX (with non-OSS version)

Open dario-loi opened this issue 2 years ago • 9 comments

Bug Report

Describe the bug

Running the command LaTeX Utilities: Edit Live Snippets file does not work whenever the extension is on a Linux machine that is running the extension on a bin installation of Visual Studio Code (not the OSS version).

The reason is apparent, the code that generates the json is hardcoded to look in the Code - OSS directory under .config, switching this line to Code solves the issue on my machine, it is however a solution that would break the extension for every other machine that actually uses the OSS version, therefore, some selection mechanism in the code should be provided

To Reproduce

Steps to reproduce the behaviour:

  1. Open the command palette (CTRL + SHIFT + P)
  2. Search for LaTeX Utilities: Edit Live Snippets file
  3. Nothing shows up.

Expected behaviour

The requested snippets .json file should show up.

Logs

Please paste the whole log messages here, not parts of ones. It is very important to identify problems. If you think the logs are unrelated, please say so.

LaTeX Utilities Output

[20:05:57] editLiveSnippetsFile [20:05:57] Error: ENOENT: no such file or directory, open '/home/dariol/.config/Code - OSS/User/latexUtilsLiveSnippets.json' [20:05:57] Error reported.

Desktop

  • Arch Linux-x86_64
  • VS Code version: 1.75.1
  • Extension version: 0.4.9

dario-loi avatar Feb 17 '23 19:02 dario-loi

https://github.com/tecosaur/LaTeX-Utilities/blob/7f96b3bad1291a6afd55a098aee9e078d6ba3984/src/components/completionWatcher.ts#L368-L374

Can you double-check if /home/dariol/.config/Code/User/latexUtilsLiveSnippets.json exisis?

leoleoasd avatar Mar 15 '23 08:03 leoleoasd

Yes, the json file is under my .config directory at the correct path, perhaps the if branch is not taken anyway (existSync returns false)?

dario-loi avatar Mar 15 '23 13:03 dario-loi

I have exactly the same issue : the command LaTeX Utilities: Edit Live Snippets file do nothing (and I don't have 'Code -OSS' but only 'Code' in the .config directory. Is there any solution ? Thanks

obrebant avatar Mar 30 '23 20:03 obrebant

The reason is that this line here is executed despite the fact that you do not have an OSS version.

It seems that the extension checks if a Code directory is present under .config, if it doesn't, it falls back to using Code - OSS instead as a .config folder, without checking if it exists or not, hence it incorrectly assumes that you have the OSS version instead.

A version of the code that doublechecks and errors out could be easily written:

let conf = path.join(process.env.HOME, '.config', codeFolder, 'User', templateName);
if (existsSync(conf)) {
    return conf;
} else {
    conf = path.join(process.env.HOME, '.config', 'Code - OSS', 'User', templateName);
    if (existsSync(conf)) {
        return conf;
    }
    else
    {
        return "";
    }
}

Alternatively, if there is a way to figure out which of the two is being used to run the extension, the .config directory could be created (its worth nothing that in my case the directory DOES exist)

@obrebant you can try a janky fix by navigating to ~/.vscode/extensions/tecosaur.latex-utilities-0.4.10/ and then by manually modifying the code in /out/main.js, which is the transpiled and minified version that contains the above lines, you can then substitute 'Code - OSS' with 'Code' in line 372, this solved the problem on my machine.

dario-loi avatar Mar 31 '23 19:03 dario-loi

Hi @dario-loi !

Thanks a lot for your reactivity. I understand the problem. I have modify the 'main.js' file as you suggest, and it works fine for me too. Nice and thank you. However, I suppose, we would make again the changes after the next update...

obrebant avatar Mar 31 '23 20:03 obrebant

Thanks @dario-loi! Can you make a PR on this?

leoleoasd avatar Apr 01 '23 03:04 leoleoasd

Unfortunately I do not know how to set up a development environment for VSCode extensions, and even then I am unable to reproduce the bug on my current system, so I am not sure if the proposed solution would be appropriate.

dario-loi avatar Apr 23 '23 11:04 dario-loi

I think it's better to migrate these settings to vscode settings. This would allow vscode's setting sync to work with custom snippets and better following vscode's guidelines

I'll implement this later

leoleoasd avatar Apr 24 '23 10:04 leoleoasd

I just noticed that my feature request (microsoft/vscode#180677) has been implemented. Now I'm putting this feature on my TODO list...

leoleoasd avatar Oct 03 '23 20:10 leoleoasd