tecosaur / LaTeX-Utilities

An add-on to LaTeX Workshop that provides some features that go beyond the bare essentials
MIT License
474 stars 28 forks source link

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

Closed dario-loi closed 6 months ago

dario-loi commented 1 year ago

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

leoleoasd commented 1 year ago

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?

dario-loi commented 1 year ago

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

obrebant commented 1 year ago

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

dario-loi commented 1 year ago

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.

obrebant commented 1 year ago

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...

leoleoasd commented 1 year ago

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

dario-loi commented 1 year ago

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.

leoleoasd commented 1 year ago

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 commented 10 months ago

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