Skip to content

Commit

Permalink
Add support for ~/ or ~\ in settings
Browse files Browse the repository at this point in the history
Fixes #99.
  • Loading branch information
valentjn committed Aug 22, 2020
1 parent 775fd5d commit 1dd44c6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
## 6.3.0 (upcoming)

- Add support for `an` article when before a formula starting with a vowel (e.g., `an $n$-dimensional problem`, fixes [#92](https://github.com/valentjn/vscode-ltex/issues/92))
- Add support for `~/` or `~\` in settings (fixes [#99](https://github.com/valentjn/vscode-ltex/issues/99))
- Fix links to documentation in various places (readme, changelog, error messages, etc.)

## 6.2.0 — “The Command Isotope” (August 7, 2020)
Expand Down
20 changes: 10 additions & 10 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,12 @@
"ltex.i18n.configuration.ltex.enabledRules.uk-UA.description": "List of additional 'uk-UA' (Ukrainian) rules that should be enabled (if disabled by default by LanguageTool).",
"ltex.i18n.configuration.ltex.enabledRules.zh-CN.markdownDescription": "List of additional `zh-CN` (Chinese) rules that should be enabled (if disabled by default by LanguageTool).",
"ltex.i18n.configuration.ltex.enabledRules.zh-CN.description": "List of additional 'zh-CN' (Chinese) rules that should be enabled (if disabled by default by LanguageTool).",
"ltex.i18n.configuration.ltex.ltex-ls.path.markdownDescription": "If set to an empty string, LTeX automatically downloads the [latest compatible release of ltex-ls from GitHub](https://github.com/valentjn/ltex-ls/releases), stores it in the folder of the extension, and uses it for the checking process. You can point this setting to an ltex-ls release you downloaded by yourself. Use the path to the root directory of ltex-ls (it contains `bin` and `lib` subdirectories). Changes require reloading the Visual Studio Code window to take effect.",
"ltex.i18n.configuration.ltex.ltex-ls.path.description": "If set to an empty string, LTeX automatically downloads the latest compatible release of ltex-ls from GitHub (see https://github.com/valentjn/ltex-ls/releases), stores it in the folder of the extension, and uses it for the checking process. You can point this setting to an ltex-ls release you downloaded by yourself. Use the path to the root directory of ltex-ls (it contains 'bin' and 'lib' subdirectories). Changes require reloading the Visual Studio Code window to take effect.",
"ltex.i18n.configuration.ltex.ltex-ls.path.markdownDescription": "If set to an empty string, LTeX automatically downloads the [latest compatible release of ltex-ls from GitHub](https://github.com/valentjn/ltex-ls/releases), stores it in the folder of the extension, and uses it for the checking process. You can point this setting to an ltex-ls release you downloaded by yourself. Use the path to the root directory of ltex-ls (it contains `bin` and `lib` subdirectories). `~` is expanded to the user's home directory. Changes require reloading the Visual Studio Code window to take effect.",
"ltex.i18n.configuration.ltex.ltex-ls.path.description": "If set to an empty string, LTeX automatically downloads the latest compatible release of ltex-ls from GitHub (see https://github.com/valentjn/ltex-ls/releases), stores it in the folder of the extension, and uses it for the checking process. You can point this setting to an ltex-ls release you downloaded by yourself. Use the path to the root directory of ltex-ls (it contains 'bin' and 'lib' subdirectories). '~' is expanded to the user's home directory. Changes require reloading the Visual Studio Code window to take effect.",
"ltex.i18n.configuration.ltex.ltex-ls.languageToolHttpServerUri.markdownDescription": "If set to a non-empty string, LTeX will not use the bundled, built-in version of LanguageTool. Instead, LTeX will connect to an external [LanguageTool HTTP server](http://wiki.languagetool.org/http-server). Set this setting to the root URI of the server, and do not append `v2/check` or similar. Note that in this mode, the settings `ltex.dictionary`, `ltex.additionalRules.languageModel`, `ltex.additionalRules.neuralNetworkModel`, and `ltex.additionalRules.word2VecModel` will not take any effect, and the `Add to dictionary` quick fix will not appear.",
"ltex.i18n.configuration.ltex.ltex-ls.languageToolHttpServerUri.description": "If set to a non-empty string, LTeX will not use the bundled, built-in version of LanguageTool. Instead, LTeX will connect to an external LanguageTool HTTP server (see http://wiki.languagetool.org/http-server for more information). Set this setting to the root URI of the server, and do not append 'v2/check' or similar. Note that in this mode, the settings 'ltex.dictionary', 'ltex.additionalRules.languageModel', 'ltex.additionalRules.neuralNetworkModel', and 'ltex.additionalRules.word2VecModel' will not take any effect, and the 'Add to dictionary' quick fix will not appear.",
"ltex.i18n.configuration.ltex.java.path.markdownDescription": "If set to an empty string and LTeX could not find Java on your computer, LTeX automatically downloads a Java distribution ([AdoptOpenJDK](https://adoptopenjdk.net/)), stores it in the folder of the extension, and uses it to run ltex-ls. You can point this setting to an existing Java installation on your computer to use that installation instead. Use the same path as you would use for the `JAVA_HOME` environment variable (it usually contains `bin` and `lib` subdirectories, amongst others). Changes require reloading the Visual Studio Code window to take effect.",
"ltex.i18n.configuration.ltex.java.path.description": "If set to an empty string and LTeX could not find Java on your computer, LTeX automatically downloads a Java distribution (AdoptOpenJDK, see https://adoptopenjdk.net/), stores it in the folder of the extension, and uses it to run ltex-ls. You can point this setting to an existing Java installation on your computer to use that installation instead. Use the same path as you would use for the 'JAVA_HOME' environment variable (it usually contains 'bin' and 'lib' subdirectories, amongst others). Changes require reloading the Visual Studio Code window to take effect.",
"ltex.i18n.configuration.ltex.java.path.markdownDescription": "If set to an empty string and LTeX could not find Java on your computer, LTeX automatically downloads a Java distribution ([AdoptOpenJDK](https://adoptopenjdk.net/)), stores it in the folder of the extension, and uses it to run ltex-ls. You can point this setting to an existing Java installation on your computer to use that installation instead. Use the same path as you would use for the `JAVA_HOME` environment variable (it usually contains `bin` and `lib` subdirectories, amongst others). `~` is expanded to the user's home directory. Changes require reloading the Visual Studio Code window to take effect.",
"ltex.i18n.configuration.ltex.java.path.description": "If set to an empty string and LTeX could not find Java on your computer, LTeX automatically downloads a Java distribution (AdoptOpenJDK, see https://adoptopenjdk.net/), stores it in the folder of the extension, and uses it to run ltex-ls. You can point this setting to an existing Java installation on your computer to use that installation instead. Use the same path as you would use for the 'JAVA_HOME' environment variable (it usually contains 'bin' and 'lib' subdirectories, amongst others). '~' is expanded to the user's home directory. Changes require reloading the Visual Studio Code window to take effect.",
"ltex.i18n.configuration.ltex.java.initialHeapSize.markdownDescription": "Initial size of the Java heap memory in megabytes (corresponds to Java's `-Xms` option, must be a positive integer). Decreasing this might decrease RAM usage of the Java process. Changes require reloading the Visual Studio Code window to take effect.",
"ltex.i18n.configuration.ltex.java.initialHeapSize.description": "Initial size of the Java heap memory in megabytes (corresponds to Java's '-Xms' option). Decreasing this might decrease RAM usage of the Java process. Changes require reloading the Visual Studio Code window to take effect.",
"ltex.i18n.configuration.ltex.java.maximumHeapSize.markdownDescription": "Maximum size of the Java heap memory in megabytes (corresponds to Java's `-Xmx` option, must be a positive integer). Decreasing this might decrease RAM usage of the Java process. If you set this too small, the Java process may exceed the heap size, in which case an `OutOfMemoryError` is thrown. Changes require reloading the Visual Studio Code window to take effect.",
Expand Down Expand Up @@ -373,12 +373,12 @@
"ltex.i18n.configuration.ltex.i18n.configurationTarget.ignoreRuleInSentence.workspaceFolder.enumDescription": "When ignoring a rule in a sentence, update the workspace folder configuration if currently in a workspace folder, otherwise update the workspace configuration if currently in a workspace, otherwise update the global configuration.",
"ltex.i18n.configuration.ltex.additionalRules.motherTongue.markdownDescription": "Optional mother tongue of the user (e.g., `\"de-DE\"`). If set, additional rules will be checked to detect false friends. False friend detection improves if a language model is supplied (see `ltex.additionalRules.languageModel`).",
"ltex.i18n.configuration.ltex.additionalRules.motherTongue.description": "Optional mother tongue of the user (e.g., \"de-DE\"). If set, additional rules will be checked to detect false friends. False friend detection improves if a language model is supplied (see 'ltex.additionalRules.languageModel').",
"ltex.i18n.configuration.ltex.additionalRules.languageModel.markdownDescription": "Optional path to a directory with rules of a language model with *n*-gram occurrence counts.",
"ltex.i18n.configuration.ltex.additionalRules.languageModel.description": "Optional path to a directory with rules of a language model with n-gram occurrence counts.",
"ltex.i18n.configuration.ltex.additionalRules.neuralNetworkModel.markdownDescription": "Optional path to a directory with rules of a pretrained neural network model.",
"ltex.i18n.configuration.ltex.additionalRules.neuralNetworkModel.description": "Optional path to a directory with rules of a pretrained neural network model.",
"ltex.i18n.configuration.ltex.additionalRules.word2VecModel.markdownDescription": "Optional path to a directory with rules of a word2vec language model.",
"ltex.i18n.configuration.ltex.additionalRules.word2VecModel.description": "Optional path to a directory with rules of a word2vec language model.",
"ltex.i18n.configuration.ltex.additionalRules.languageModel.markdownDescription": "Optional path to a directory with rules of a language model with *n*-gram occurrence counts. `~` is expanded to the user's home directory.",
"ltex.i18n.configuration.ltex.additionalRules.languageModel.description": "Optional path to a directory with rules of a language model with n-gram occurrence counts. '~' is expanded to the user's home directory.",
"ltex.i18n.configuration.ltex.additionalRules.neuralNetworkModel.markdownDescription": "Optional path to a directory with rules of a pretrained neural network model. `~` is expanded to the user's home directory.",
"ltex.i18n.configuration.ltex.additionalRules.neuralNetworkModel.description": "Optional path to a directory with rules of a pretrained neural network model. '~' is expanded to the user's home directory.",
"ltex.i18n.configuration.ltex.additionalRules.word2VecModel.markdownDescription": "Optional path to a directory with rules of a word2vec language model. `~` is expanded to the user's home directory.",
"ltex.i18n.configuration.ltex.additionalRules.word2VecModel.description": "Optional path to a directory with rules of a word2vec language model. '~' is expanded to the user's home directory.",
"ltex.i18n.configuration.ltex.sentenceCacheSize.markdownDescription": "Size of the LanguageTool `ResultCache` in sentences (must be a positive integer). If only a small portion of the text changed (e.g., a single key press in the editor), LanguageTool uses the cache to avoid rechecking the complete text. LanguageTool internally splits the text into sentences, and sentences that have already been checked are skipped. Decreasing this might decrease RAM usage of the Java process. If you set this too small, checking time may increase significantly. Changes require reloading the Visual Studio Code window to take effect.",
"ltex.i18n.configuration.ltex.sentenceCacheSize.description": "Size of the LanguageTool 'ResultCache' in sentences. If only a small portion of the text changed (e.g., a single key press in the editor), LanguageTool uses the cache to avoid rechecking the complete text. LanguageTool internally splits the text into sentences, and sentences that have already been checked are skipped. Decreasing this might decrease RAM usage of the Java process. If you set this too small, checking time may increase significantly. Changes require reloading the Visual Studio Code window to take effect.",
"ltex.i18n.configuration.ltex.diagnosticSeverity.markdownDescription": "Severity of the diagnostics corresponding to the grammar and spelling errors. Allows to control how and where the diagnostics appear in Visual Studio Code. One of `\"error\"`, `\"warning\"`, `\"information\"`, and `\"hint\"`.",
Expand Down
14 changes: 11 additions & 3 deletions src/Dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import extractZip from 'extract-zip';
import * as Fs from 'fs';
import * as Http from 'http';
import * as Https from 'https';
import * as Os from 'os';
import * as Path from 'path';
import * as SemVer from 'semver';
import * as Tar from 'tar';
Expand Down Expand Up @@ -45,6 +46,12 @@ export default class Dependencies {
return ((path != null) && (path.length > 0));
}

private static normalizePath(path: string | null): string | null {
if (path == null) return null;
const homeDirPath: string = Os.homedir();
return path.replace(/^~($|\/|\\)/, `${homeDirPath}$1`);
}

private static parseUrl(urlStr: string): Https.RequestOptions {
const url: Url.UrlWithStringQuery = Url.parse(urlStr);
return {
Expand Down Expand Up @@ -393,7 +400,7 @@ export default class Dependencies {
// try 1: use lib/ (don't download)
// try 2: download and use lib/
Logger.log('');
this._ltexLsPath = workspaceConfig.get('ltex-ls.path', '');
this._ltexLsPath = Dependencies.normalizePath(workspaceConfig.get('ltex-ls.path', ''));

if (Dependencies.isValidPath(this._ltexLsPath)) {
Logger.log(i18n('ltexLtexLsPathSetTo', this._ltexLsPath));
Expand Down Expand Up @@ -434,7 +441,8 @@ export default class Dependencies {
for (let i: number = 0; i < 6; i++) {
try {
Logger.log('');
this._javaPath = Dependencies.getRenamedSetting(workspaceConfig, 'java.path', 'javaHome');
this._javaPath = Dependencies.normalizePath(Dependencies.getRenamedSetting(
workspaceConfig, 'java.path', 'javaHome'));

if (Dependencies.isValidPath(this._javaPath)) {
Logger.log(i18n('ltexJavaPathSetTo', this._javaPath));
Expand Down Expand Up @@ -597,7 +605,7 @@ export default class Dependencies {
if (Dependencies.isValidPath(this._javaPath)) {
env['JAVA_HOME'] = this._javaPath!;
} else if ((env['LTEX_JAVA_HOME'] != null) && Dependencies.isValidPath(env['LTEX_JAVA_HOME'])) {
env['JAVA_HOME'] = env['LTEX_JAVA_HOME'];
env['JAVA_HOME'] = Dependencies.normalizePath(env['LTEX_JAVA_HOME'])!;
}

const isWindows: boolean = (process.platform === 'win32');
Expand Down

0 comments on commit 1dd44c6

Please sign in to comment.