Skip to content

Commit

Permalink
Improve the linting diagnostics so that the quick fix is more easily …
Browse files Browse the repository at this point in the history
…triggered.
  • Loading branch information
Robbie Ostermann committed Sep 9, 2022
1 parent 5065829 commit 85a1b60
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to the "sqlfluff" extension will be documented in this file.

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [0.0.9] - 2022-09-08

- Add the quick fix option to view the SQLFluff documention on the SQLFluff website.
- Fix the diagnostics so the quick fix can be triggered by any location on the problem word.

## [0.0.8] - 2022-09-08

- This release rewrites some of the extension code, but should leave the functionality the same.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vscode-sqlfluff",
"displayName": "sqlfluff",
"version": "0.0.8",
"version": "0.0.9",
"description": "A linter and auto-formatter for SQLfluff, a popular linting tool for SQL and dbt.",
"publisher": "dorzey",
"icon": "images/icon.png",
Expand Down
20 changes: 12 additions & 8 deletions src/features/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,20 @@ export class LinterProvider implements Linter {
if (filePaths) {
filePaths.forEach((filePath: FilePath) => {
filePath.violations.forEach((violation: Violation) => {
const range = new Range(
const path = filePath.filepath;
const editorPath = normalize(vscode.window.activeTextEditor.document.uri.fsPath);
const violationPosition = new vscode.Position(violation.line_no - 1, violation.line_pos - 1);
let range = new Range(
violation.line_no - 1,
violation.line_pos,
violation.line_pos - 1,
violation.line_no - 1,
violation.line_pos
violation.line_pos - 1
);

if (editorPath.includes(path)) {
range = vscode.window.activeTextEditor.document.getWordRangeAtPosition(violationPosition) || range;
}

const diagnostic = new Diagnostic(
range,
violation.description,
Expand All @@ -47,11 +55,6 @@ export class LinterProvider implements Linter {
diagnostic.code = violation.code;
diagnostic.source = "sqlfluff";
diagnostics.push(diagnostic);

const hover = new vscode.Hover(
"[rule L007](https://docs.sqlfluff.com/en/stable/rules.html#sqlfluff.rules.Rule_L007)",
range
);
});
});
}
Expand All @@ -62,6 +65,7 @@ export class LinterProvider implements Linter {
}

interface FilePath {
filepath: string;
violations: Array<Violation>;
}

Expand Down

0 comments on commit 85a1b60

Please sign in to comment.