Skip to content

Commit

Permalink
Override java VM & EOL fix (#63)
Browse files Browse the repository at this point in the history
- New settings **groovyLint.java.executable** and **groovyLint.java.options**
- Upgrade to [npm-groovy-lint](https://www.npmjs.com/package/npm-groovy-lint) v5.5.0
  - Allow to override java executable and options [(#54)](#54)
  - Use os.EOL [(#65)](nvuillam/npm-groovy-lint#65) solving  [(#63)](nvuillam/npm-groovy-lint#63) --fix for indentation adds CRLF line-endings to all files it touches
  • Loading branch information
nvuillam authored Jul 12, 2020
1 parent 3cc534b commit 596d57f
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 13 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [0.18.0] 2020-07-12

- New settings **groovyLint.java.executable** and **groovyLint.java.options**
- Upgrade to [npm-groovy-lint](https://www.npmjs.com/package/npm-groovy-lint) v5.5.0
- Allow to override java executable and options [(#54)](https:/nvuillam/vscode-groovy-lint/issues/54)
- Use os.EOL [(#65)](https:/nvuillam/npm-groovy-lint/pull/65) solving [(#63)](https:/nvuillam/npm-groovy-lint/issues/63) --fix for indentation adds CRLF line-endings to all files it touches

## [0.17.1] 2020-07-05

Fixes:
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ Formatting and Auto-fix are still in beta version, please post an [issue](https:
| `groovyLint.fix.trigger` | Run the fixer on save (onSave), or on user request | user |
| `groovyLint.basic.loglevel` | Linting error level (error, warning,info) | info |
| `groovyLint.basic.verbose` | Turn on to have verbose logs | false |
| `groovyLint.basic.config` | [NPM groovy lint configuration file](https:/nvuillam/npm-groovy-lint#configuration) | .groovylintrc.js |
| `groovyLint.basic.config` | [NPM groovy lint configuration file](https:/nvuillam/npm-groovy-lint#configuration) | .groovylintrc.json |
| `groovyLint.debug.enable` | Display more logs in VsCode Output panel (select "GroovyLint") for issue investigation | false |
| `groovyLint.java.executable` | Override java executable to use <br/>Example: C:\\Program Files\\Java\\jdk1.8.0_144\\bin\\java.exe | java |
| `groovyLint.java.options` | Override java options to use | "-Xms256m,-Xmx2048m" |
| `groovyLint.insight.enable` | Allow to send anonymous usage statistics used only to improve the tool (we will of course never send your code) | true |

## Troubleshooting
Expand All @@ -77,7 +79,14 @@ Please follow [Contribution instructions](https:/nvuillam/vscode-gro

## Release Notes

## [0.17.1] 2020-07-05
### [0.18.0] 2020-07-12

- New settings **groovyLint.java.executable** and **groovyLint.java.options**
- Upgrade to [npm-groovy-lint](https://www.npmjs.com/package/npm-groovy-lint) v5.5.0
- Allow to override java executable and options [(#54)](https:/nvuillam/vscode-groovy-lint/issues/54)
- Use os.EOL [(#65)](https:/nvuillam/npm-groovy-lint/pull/65) solving [(#63)](https:/nvuillam/npm-groovy-lint/issues/63) --fix for indentation adds CRLF line-endings to all files it touches

### [0.17.1] 2020-07-05

Fixes:

Expand Down
2 changes: 1 addition & 1 deletion package-json-schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"title": "JSON schema for ESLint configuration files",
"title": "JSON schema for GroovyLint configuration files",
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"definitions": {
Expand Down
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,16 @@
"default": false,
"description": "Display debugging info in output panel"
},
"groovyLint.java.executable": {
"scope": "resource",
"type": "string",
"description": "Path to java executable if you do not want to use system default"
},
"groovyLint.java.options": {
"scope": "resource",
"type": "string",
"description": "Comma separated arguments for java (default \"-Xms256m,-Xmx2048m\")"
},
"groovyLint.insight.enable": {
"scope": "resource",
"type": "boolean",
Expand All @@ -264,4 +274,4 @@
}
}
}
}
}
6 changes: 3 additions & 3 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"devDependencies": {
"@types/fs-extra": "^8.1.0",
"npm-groovy-lint": "^5.4.1",
"npm-groovy-lint": "^5.5.0",
"vscode-languageserver-textdocument": "^1.0.1"
}
}
16 changes: 13 additions & 3 deletions server/src/DocumentsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { executeLinter } from './linter';
import { applyQuickFixes, applyQuickFixesInFile, disableErrorWithComment, disableErrorForProject } from './codeActions';
import { isTest, showRuleDocumentation } from './clientUtils';
import { URI } from 'vscode-uri';
import os = require('os');
import path = require('path');
import { StatusNotification, VsCodeGroovyLintSettings } from './types';
import { lintFolder } from './folder';
Expand Down Expand Up @@ -298,6 +299,14 @@ export class DocumentsManager {
return [options.format, options.fix].includes(true);
}

// Cancel all current and future document validations
async cancelAllDocumentValidations() {
this.queuedLints = [];
for (const currLinted of this.currentlyLinted) {
await this.cancelDocumentValidation(currLinted.uri);
}
}

// Cancels a document validation
async cancelDocumentValidation(textDocumentUri: string) {
// Remove duplicates in queue ( ref: https://stackoverflow.com/a/56757215/7113625 )
Expand Down Expand Up @@ -380,9 +389,10 @@ export class DocumentsManager {

// Split source string into array of lines
getTextDocumentLines(textDocument: TextDocument) {
return textDocument.getText()
.replace(/\r?\n/g, "\r\n")
.split("\r\n");
let normalizedString = textDocument.getText() + "";
normalizedString = normalizedString.replace(/\r/g, "");
normalizedString = normalizedString.replace(/\n/g, os.EOL);
return normalizedString.split(os.EOL);
}

// Update diagnostics on client and store them in docsDiagnostics field
Expand Down
3 changes: 2 additions & 1 deletion server/src/clientUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TextDocumentEdit, WorkspaceEdit, ShowMessageRequestParams, MessageType,
import { DocumentsManager } from './DocumentsManager';
import { OpenNotification } from './types';
const debug = require("debug")("vscode-groovy-lint");
import os = require("os");

const defaultDocUrl = "https://codenarc.github.io/CodeNarc/codenarc-rule-index.html";

Expand Down Expand Up @@ -37,7 +38,7 @@ export function createTextEdit(docManager: DocumentsManager, textDocument: TextD
start: { line: 0, character: 0 },
end: { line: allLines.length - 1, character: allLines[allLines.length - 1].length }
},
newText: allLines.join('\r\n')
newText: allLines.join(os.EOL)
};
}
// Replace line at position
Expand Down
7 changes: 7 additions & 0 deletions server/src/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ export async function executeLinter(textDocument: TextDocument, docManager: Docu
npmGroovyLintConfig.rulesetsoverridetype = "appendConfig";
}

// Java & options override
if (settings.java.executable) {
npmGroovyLintConfig.javaexecutable = settings.java.executable;
}
if (settings.java.options) {
npmGroovyLintConfig.javaoptions = settings.java.options;
}

// If source has not changed, do not lint again
if (isSimpleLintIdenticalSource === true) {
Expand Down
4 changes: 3 additions & 1 deletion server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ connection.onExit(async () => {
// Lint again all opened documents in configuration changed
// wait N seconds in case a new config change arrive, run just after the last one
connection.onDidChangeConfiguration(async (change) => {
debug(`change configuration event received: lint again all open documents`);
debug(`change configuration event received: restart server and lint again all open documents`);
await new NpmGroovyLint({ killserver: true }, {}).run();
await docManager.cancelAllDocumentValidations();
await docManager.lintAgainAllOpenDocuments();
});

Expand Down
1 change: 1 addition & 0 deletions server/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface VsCodeGroovyLintSettings {
fix?: any;
format?: any;
basic?: any;
java?: any
insight?: any;
tabSize?: number;
}

0 comments on commit 596d57f

Please sign in to comment.