Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make --settings-file compatible with flattened JSON like VS Code's settings.json #91

Closed
hdorgeval opened this issue Jul 25, 2021 · 5 comments
Assignees
Labels
1-feature-request ✨ Issue type: Request for a desirable, nice-to-have feature 3-fixed Issue resolution: Issue has been fixed on the develop branch
Milestone

Comments

@hdorgeval
Copy link

Hi @valentjn, I just tried the new option --input-documents and it works great. Thank you so much for providing this feature!

Nonetheless, It is not clear how to use this new option with the --settings-file option.

My use case is that I would like to re-use the workspace settings files that have been generated in VSCode:

Screen Shot 2021-07-25 at 17 08 18

It would be great if you could give some help.

Thanks.

@hdorgeval hdorgeval added the 1-question ❓ Issue type: General or specific question about LTeX label Jul 25, 2021
@valentjn
Copy link
Owner

There is an example in the docs under --settings-file.

You have to remove the ltex. prefixes to make it work (this stems from the configuration format the LSP mandates). Now that I think about it, you probably also have to unfold everything (that part is missing in the docs). So {"ltex.latex.commands": ...} becomes {"latex": {"commands": ...}}.

I see why this could confuse people, and it's a good idea to support both possibilities. Keep in mind, though, that VS Code is not the only editor LTEX LS supports; other editors might have different setting formats.

@hdorgeval
Copy link
Author

hdorgeval commented Jul 25, 2021

Hi @valentjn, thanks for your answer. Now I understand more.

For those who will land on this question/issue, here is the excerpt of the settings file that should be given to the --settings-file option (in my use case the input document is in french):

{
  "language": "fr",
  "dictionary": {
    "fr": [
      "Tehemten",
      "Akwan",
      "Rustem",
      "Touran",
      "Raksch",
      "farsangs",
      "Divs",
      // other words omitted for brevity
    ]
  },
  "hiddenFalsePositives": {
    "fr": [
      {
        "rule": "D_N",
        "sentence": "^\\QLorsqu'il fut revenu auprès de la source, méditant dans son âme guerrière de nouvelles luttes, le Div Akwan l'accosta de nouveau et lui dit :\\E$"
      },
      {
        "rule": "D_N",
        "sentence": "^\\QTehemten répondit aux paroles du Div par un mugissement de lion , détacha du crochet son lacet roulé, le lança et prit le Div au milieu du corps.\\E$"
      },
      // other rules omitted for brevity
    ]
  }
}

Basically, it is just a copy/paste of the files generated by the VSCode extension vscode-ltex under the .vscode folder.

I will provide soon in this discussion a node-js script that automatically create that settings files from the ones (ltex.dictionary.fr.txt, ltex.hiddenFalsePositives.fr.txt, settings.json) found in the .vscode folder

@hdorgeval hdorgeval changed the title How to use VSCode workspace settings with the new --input-documents cli option ? How to use vscode-ltex settings with the new --input-documents / --settings-file cli options ? Jul 26, 2021
@hdorgeval
Copy link
Author

Here is the script that builds the needed settings file from what has been generated by the VSCode extension (this sample code handles only french files):

  const ltexFrDictionaryFile = path.join(process.cwd(), '.vscode', 'ltex.dictionary.fr.txt');
  const frDictionary = readAllLinesInFile(ltexFrDictionaryFile).filter(
    (line) => line && line.length > 0,
  );

  const frFalsePositiveFile = path.join(
    process.cwd(),
    '.vscode',
    'ltex.hiddenFalsePositives.fr.txt',
  );
  const frFalsePositives = readAllLinesInFile(frFalsePositiveFile)
    .filter((line) => line && line.length > 0)
    .map((rawRule) => JSON.parse(rawRule));

  const frLtexLsSettings = {
    language: 'fr',
    dictionary: { fr: frDictionary },
    hiddenFalsePositives: { fr: frFalsePositives },
  };

  writeFileSync(
    path.join(process.cwd(), 'ltex-settings.fr.json'),
    JSON.stringify(frLtexLsSettings, null, 2),
  );

readAllLinesInFile:

export const readAllLinesInFile = (filePath: PathLike): string[] => {
  const lines = readFileSync(filePath, 'utf8').split(/\n|\r/);
  return lines;
};

@valentjn
Copy link
Owner

valentjn commented Aug 5, 2021

LTEX LS can now parse flattened JSON objects as well, with or without ltex. prefix. Look in the readme/CLI help for examples.

Note that the settings JSON of the screenshot in the description of this issue won't work though, because that's not valid JSON (has trailing commas). Only valid JSON is supported (no trailing commas, no comments).

@valentjn valentjn closed this as completed Aug 5, 2021
@valentjn valentjn self-assigned this Aug 5, 2021
@valentjn valentjn added this to the 13.0.0 milestone Aug 5, 2021
@valentjn valentjn added 1-feature-request ✨ Issue type: Request for a desirable, nice-to-have feature 3-fixed Issue resolution: Issue has been fixed on the develop branch and removed 1-question ❓ Issue type: General or specific question about LTeX labels Aug 5, 2021
@valentjn valentjn changed the title How to use vscode-ltex settings with the new --input-documents / --settings-file cli options ? Make --settings-file compatible with flattened JSON like VS Code's settings.json Aug 6, 2021
@valentjn
Copy link
Owner

Feature released in 13.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1-feature-request ✨ Issue type: Request for a desirable, nice-to-have feature 3-fixed Issue resolution: Issue has been fixed on the develop branch
Projects
None yet
Development

No branches or pull requests

2 participants