Skip to content

Commit 3085859

Browse files
v3.1.5: Fix bug with ignoring diagnostics
1 parent 7dfd941 commit 3085859

File tree

5 files changed

+39
-18
lines changed

5 files changed

+39
-18
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
All notable changes to the "sqlfluff" extension will be documented in this file.
44

5+
## [3.1.5] - 2024-08-16
6+
- Fix bug with ignoring diagnostics
7+
58
## [3.1.4] - 2024-07-25
69

710
- Correctly parse the sqlfluff version number. [Issue](https://github.com/sqlfluff/vscode-sqlfluff/issues/151)

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vscode-sqlfluff",
33
"displayName": "sqlfluff",
4-
"version": "3.1.4",
4+
"version": "3.1.5",
55
"description": "A linter and auto-formatter for SQLfluff, a popular linting tool for SQL and dbt.",
66
"publisher": "dorzey",
77
"icon": "images/icon.png",

src/features/helper/utilities.ts

+20-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Variables from "./types/variables";
66
export default class Utilities {
77
static outputChannel = vscode.window.createOutputChannel("SQLFluff");
88

9-
public static appendHyphenatedLine(newLines = true) {
9+
static appendHyphenatedLine(newLines = true) {
1010
if (newLines) {
1111
Utilities.outputChannel.appendLine("\n------------------------------------------------------------\n");
1212
} else {
@@ -32,7 +32,7 @@ export default class Utilities {
3232
return command;
3333
}
3434

35-
public static normalizePath(path: string, allowEscapes = false): string {
35+
static normalizePath(path: string, allowEscapes = false): string {
3636
if (path === undefined) {
3737
return path;
3838
}
@@ -47,11 +47,11 @@ export default class Utilities {
4747
return path.replace(/\\+/g, "/");
4848
}
4949

50-
public static async sleep(milliseconds: number) {
50+
static async sleep(milliseconds: number) {
5151
return new Promise((resolve) => setTimeout(resolve, milliseconds));
5252
}
5353

54-
public static parseVersion(versionString: string): ParsedVersion {
54+
static parseVersion(versionString: string): ParsedVersion {
5555
const parsedVersion: ParsedVersion = {
5656
major: 0,
5757
minor: 0,
@@ -86,7 +86,21 @@ export default class Utilities {
8686
return parsedVersion;
8787
}
8888

89-
public static isNumber = (value: any, cast = true) =>
89+
static isNumber = (value: any, cast = true) =>
9090
typeof value === "number" || (cast ? !isNaN(Number(value)) : !isNaN(value));
91-
public static toNumber = (value: any, fallback = 0) => (Utilities.isNumber(value) ? Number(value) : fallback);
91+
92+
static toNumber = (value: any, fallback = 0) => (Utilities.isNumber(value) ? Number(value) : fallback);
93+
94+
/**
95+
* Get the diagnostic code without the description
96+
* @param diagnostic - VSCode Diagnostic
97+
* @returns Diagnostic code without description
98+
*/
99+
static getDiagnosticCode = (diagnostic: vscode.Diagnostic) =>
100+
Utilities.extractBeforeColon(diagnostic.code?.toString() ?? "");
101+
102+
private static extractBeforeColon(input: string): string {
103+
const match = input.match(/^(.*?):/);
104+
return match ? match[1] : "";
105+
}
92106
}

src/features/providers/linter/actions/hover.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/* eslint-disable @typescript-eslint/no-unused-vars */
22
import * as vscode from "vscode";
33

4+
import Utilities from "../../../helper/utilities";
5+
46
export default class HoverProvider implements vscode.HoverProvider {
57
public provideHover(
68
document: vscode.TextDocument,
79
position: vscode.Position,
8-
token: vscode.CancellationToken,
10+
token: vscode.CancellationToken
911
): vscode.ProviderResult<vscode.Hover> {
1012
const editor = vscode.window.activeTextEditor;
1113
const diagnostics = vscode.languages.getDiagnostics(document.uri);
@@ -30,7 +32,8 @@ export default class HoverProvider implements vscode.HoverProvider {
3032
// Link to the rule permalinks so that if the rule docs move in the future that
3133
// we don't have to update the links here. We rely on the docs internally redirecting
3234
// us to the appropriate location.
33-
const path = `https://docs.sqlfluff.com/en/stable/perma/rule/${diagnostic.code}.html`;
35+
// const path = `https://docs.sqlfluff.com/en/stable/perma/rule/${Utilities.getDiagnosticCode(diagnostic)}.html`;
36+
const path = `https://docs.sqlfluff.com/en/stable/rules.html#sqlfluff.rules.sphinx.Rule_${diagnostic.code}`;
3437
const markdownString = new vscode.MarkdownString();
3538

3639
markdownString.appendMarkdown(`[View Documentation](${path}) for Rule ${diagnostic.code}.\n`);

src/features/providers/linter/actions/quickFix.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as vscode from "vscode";
33

44
import { EXCLUDE_RULE, EXCLUDE_RULE_WORKSPACE } from "../../../commands/excludeRules";
55
import Configuration from "../../../helper/configuration";
6+
import Utilities from "../../../helper/utilities";
67

78
export default class QuickFixProvider implements vscode.CodeActionProvider {
89
public static readonly providedCodeActionKind = [vscode.CodeActionKind.QuickFix];
@@ -11,7 +12,7 @@ export default class QuickFixProvider implements vscode.CodeActionProvider {
1112
document: vscode.TextDocument,
1213
range: vscode.Range | vscode.Selection,
1314
context: vscode.CodeActionContext,
14-
token: vscode.CancellationToken,
15+
token: vscode.CancellationToken
1516
): vscode.CodeAction[] {
1617
const noqaSingleRules: vscode.CodeAction[] = [];
1718
const noqaAllRules: vscode.CodeAction[] = [];
@@ -21,7 +22,7 @@ export default class QuickFixProvider implements vscode.CodeActionProvider {
2122
if (Configuration.noqaEnabled()) {
2223
const noqaDisabledRules = Configuration.noqaDisabledRules();
2324
context.diagnostics.forEach((diagnostic) => {
24-
if (diagnostic.code && !noqaDisabledRules.includes(diagnostic.code.toString())) {
25+
if (diagnostic.code && !noqaDisabledRules.includes(Utilities.getDiagnosticCode(diagnostic))) {
2526
const singleRuleCodeAction = this.createNoqaCodeFix(document, diagnostic, false);
2627
const allRulesCodeAction = this.createNoqaCodeFix(document, diagnostic, true);
2728
noqaSingleRules.push(singleRuleCodeAction);
@@ -44,7 +45,7 @@ export default class QuickFixProvider implements vscode.CodeActionProvider {
4445
private createNoqaCodeFix(
4546
document: vscode.TextDocument,
4647
diagnostic: vscode.Diagnostic,
47-
allRules: boolean,
48+
allRules: boolean
4849
): vscode.CodeAction {
4950
const title = allRules ? "Ignore all rules for this line" : `Ignore rule ${diagnostic.code} for this line`;
5051
const fix = new vscode.CodeAction(title, vscode.CodeActionKind.QuickFix);
@@ -54,7 +55,7 @@ export default class QuickFixProvider implements vscode.CodeActionProvider {
5455
const line = document.lineAt(diagnostic.range.start.line);
5556
const endPosition = new vscode.Position(
5657
line.range.end.line,
57-
line.range.end.character > 0 ? line.range.end.character : 0,
58+
line.range.end.character > 0 ? line.range.end.character : 0
5859
);
5960
const noqaREGEX = /\s*-- noqa(?::(\s?\w\d{3},?)*)?.*/;
6061
const noqa = noqaREGEX.exec(line.text);
@@ -67,20 +68,20 @@ export default class QuickFixProvider implements vscode.CodeActionProvider {
6768
if (noqa.length > 1) {
6869
if (noqa[1]) {
6970
if (noqa[1].endsWith(",")) {
70-
fix.edit.insert(document.uri, endPosition, ` ${diagnostic.code}`);
71+
fix.edit.insert(document.uri, endPosition, ` ${Utilities.getDiagnosticCode(diagnostic)}`);
7172
} else {
72-
fix.edit.insert(document.uri, endPosition, `, ${diagnostic.code}`);
73+
fix.edit.insert(document.uri, endPosition, `, ${Utilities.getDiagnosticCode(diagnostic)}`);
7374
}
7475
} else {
75-
fix.edit.insert(document.uri, endPosition, `: ${diagnostic.code}`);
76+
fix.edit.insert(document.uri, endPosition, `: ${Utilities.getDiagnosticCode(diagnostic)}`);
7677
}
7778
}
7879
}
7980
} else {
8081
if (allRules) {
8182
fix.edit.insert(document.uri, endPosition, " -- noqa");
8283
} else {
83-
fix.edit.insert(document.uri, endPosition, ` -- noqa: ${diagnostic.code}`);
84+
fix.edit.insert(document.uri, endPosition, ` -- noqa: ${Utilities.getDiagnosticCode(diagnostic)}`);
8485
}
8586
}
8687

@@ -94,7 +95,7 @@ export default class QuickFixProvider implements vscode.CodeActionProvider {
9495
command: global ? EXCLUDE_RULE : EXCLUDE_RULE_WORKSPACE,
9596
title: title,
9697
tooltip: `This will exclude the rule ${diagnostic.code} in the ${global ? "Global" : "Workspace"} Settings`,
97-
arguments: [diagnostic.code],
98+
arguments: [Utilities.getDiagnosticCode(diagnostic)],
9899
};
99100
action.diagnostics = [diagnostic];
100101

0 commit comments

Comments
 (0)