Skip to content
This repository has been archived by the owner on Sep 28, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1 from adamvoss/all-languages
Browse files Browse the repository at this point in the history
Add support for all languages by recognizing language support extensions
  • Loading branch information
adamvoss authored Jun 12, 2017
2 parents a59724b + d929d52 commit 611d0d2
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ test/**
src/**
**/*.map
.gitignore
.gitattributes
.gitmodules
.travis.yml
tsconfig.json
*.vsix
lib/**
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Change Log

## 0.0.2
- Allows any LanguageTool supported language to be used through the use of supplemental extensions
- Removes built-in English support

## 0.0.1
- Initial release
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# LanguageTool Extension for Visual Studio Code

Provides offline grammar checking in Visual Studio Code using [LanguageTool](https://languagetool.org/) via the [LanguageTool Language Server](https://github.com/adamvoss/languagetool-languageserver).
**NOTICE: as of v0.0.2, this extension does not include any languages. You MUST install a [language support extension][lang-exts].**
___
Provides offline grammar checking in Visual Studio Code using [LanguageTool](https://languagetool.org/) via the [LanguageTool Language Server](https://github.com/adamvoss/languagetool-languageserver). This extension provides only the core functionality. You must [install extensions containing the language rules for each language you wish to be able to check][lang-exts].

## Features
* Issue highlighting with hover description.
* Replacement suggestions.
* Checks **plaintext** and **markdown**.
* Supports English and country variants.
- The code supports all LanguageTool languages, but they could not all be shipped due to size limitations of the Visual Studio Marketplace.

* Support **over than 20 languages** according to which [language support extensions][lang-exts] are installed.

## Requirements
Java 8+ is required.
Expand All @@ -20,7 +20,10 @@ This extension contributes the following settings:
* `languageTool.language`: Set to the short code for the language to check. For supported languages see the [list of languages at LanguageTool.org](https://languagetool.org/languages/).

## Contributing
This repository uses git submodules. After cloning be sure to run `git submodule update --init`.
Contributions welcome!
This repository uses git submodules. After cloning, be sure to run `git submodule update --init`.

## Known Issues
Please report issues on [GitHub](https://github.com/adamvoss/vscode-languagetool).
Please report issues or submit pull requests on [GitHub](https://github.com/adamvoss/vscode-languagetool).

[lang-exts]: https://marketplace.visualstudio.com/search?term=LanguageTool&target=VSCode
2 changes: 1 addition & 1 deletion lib/languagetool-languageserver
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"description": "LanguageTool grammar checking for Visual Studio Code.",
"author": "Adam Voss",
"license": "Apache-2.0",
"version": "0.0.1",
"version": "0.0.2",
"publisher": "adamvoss",
"repository": {
"url": "https://github.com/adamvoss/vscode-languagetool"
},
"icon": "img/LanguageTool-Icon.png",
"galleryBanner": {
"color": "#6565f6",
"theme": "light"
"theme": "dark"
},
"engines": {
"vscode": "^1.8.0"
Expand Down
41 changes: 39 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,37 @@ import { LanguageClient, LanguageClientOptions, SettingMonitor, StreamInfo } fro

export function activate(context: ExtensionContext) {

function discoverExtensions() {
const extensionsDir = path.resolve(context.extensionPath, '..')

const installedExtensions = fs.readdirSync(extensionsDir)

const extensionRegEx = /^adamvoss\.vscode-languagetool-(?:.*)-(?:.*?)$/
return installedExtensions.filter(s => extensionRegEx.test(s))
}

function buildDesiredClasspath() {
const isWindows = process.platform === 'win32';

const joinCharacter = isWindows ? ';' : ':'

const additionalPaths = discoverExtensions()
.map(p => path.resolve(context.extensionPath, '..', p, 'lib', '*'))
.join(joinCharacter);

let desiredClasspath = path.join('lib', '*');
if (additionalPaths) {
desiredClasspath += joinCharacter + additionalPaths
}
return desiredClasspath
}

function setClasspath(text: String, desiredClasspath: String): String {
const classpathRegexp = /^((?:set )?CLASSPATH=[%$]APP_HOME%?[\\\/])(.*)$/m

return text.replace(classpathRegexp, `$1${desiredClasspath}`)
}

function createServer(): Promise<StreamInfo> {
return new Promise((resolve, reject) => {
var server = net.createServer((socket) => {
Expand All @@ -33,9 +64,15 @@ export function activate(context: ExtensionContext) {
// Start the child java process
let options = { cwd: workspace.rootPath };

let script = path.resolve(context.extensionPath, 'lib', 'languagetool-languageserver', 'build', 'install', 'languagetool-languageserver', 'bin', isWindows ? 'languagetool-languageserver.bat' : 'languagetool-languageserver')
const scriptDir = path.resolve(context.extensionPath, 'lib', 'languagetool-languageserver', 'build', 'install', 'languagetool-languageserver', 'bin')
let originalScript = path.resolve(scriptDir, isWindows ? 'languagetool-languageserver.bat' : 'languagetool-languageserver')
const newScript = path.resolve(scriptDir, isWindows ? 'languagetool-languageserver-live.bat' : 'languagetool-languageserver-live')

const scriptText = fs.readFileSync(originalScript, "utf8")
const newText = setClasspath(scriptText, buildDesiredClasspath())
fs.writeFileSync(newScript, newText, { mode: 0o777 })

let process = child_process.spawn(script, [server.address().port.toString()], options);
let process = child_process.spawn(newScript, [server.address().port.toString()], options);

// Send raw output to a file
if (!fs.existsSync(context.storagePath))
Expand Down

0 comments on commit 611d0d2

Please sign in to comment.