From 4b74c2b54bf42fac50dcf675415d346a523de01f Mon Sep 17 00:00:00 2001 From: Robert Ostermann Date: Sat, 15 Jul 2023 12:16:02 -0500 Subject: [PATCH] v2.3.6 --- CHANGELOG.md | 5 ++ package.json | 106 ++++++++++++++++----------- src/extension.ts | 8 +- src/features/helper/configuration.ts | 40 +++++++--- src/features/linter.ts | 2 +- test/.vscode/settings.json | 12 ++- test/suite/test_sql/markdown.md | 21 ++++++ 7 files changed, 133 insertions(+), 61 deletions(-) create mode 100644 test/suite/test_sql/markdown.md diff --git a/CHANGELOG.md b/CHANGELOG.md index d1e3545..e39b8a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. +## [2.3.6] - 2023-07-15 + +- Add the `sqlfluff.format.languages` setting to allow for users to determine which languages the formatting activates for +- Add the `sqlfluff.linter.languages` setting to allow for users to determine which languages the linting activates for + ## [2.3.5] - 2023-07-14 - Add the ability to `Format Selection` diff --git a/package.json b/package.json index 5c7f6ff..5e390d6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vscode-sqlfluff", "displayName": "sqlfluff", - "version": "2.3.5", + "version": "2.3.6", "description": "A linter and auto-formatter for SQLfluff, a popular linting tool for SQL and dbt.", "publisher": "dorzey", "icon": "images/icon.png", @@ -30,11 +30,7 @@ "snowflake-sql" ], "activationEvents": [ - "onLanguage:sql", - "onLanguage:sql-bigquery", - "onLanguage:jinja-sql", - "onLanguage:postgres", - "onLanguage:snowflake-sql" + "onStartupFinished" ], "main": "./out/src/extension.js", "contributes": { @@ -99,44 +95,6 @@ }, "markdownDescription": "DEPRECATED: Use sqlfluff.env.environmentVariables" }, - "sqlfluff.env.environmentVariables": { - "type": "array", - "default": [ - { - "key": "EXAMPLE_KEY", - "value": "example_value" - } - ], - "items": { - "type": "object", - "additionalProperties": false, - "required": [ - "key", - "value" - ], - "properties": { - "key": { - "type": "string", - "markdownDescription": "The key for the environment variable." - }, - "value": { - "type": "string", - "markdownDescription": "The value for the environment variable." - } - } - }, - "markdownDescription": "Set the environment variables for the linter and formatter." - }, - "sqlfluff.env.customDotEnvFiles": { - "type": "array", - "default": [], - "description": "Load the .env file from the specified paths." - }, - "sqlfluff.env.useDotEnvFile": { - "type": "boolean", - "default": false, - "description": "Load the .env file from the working directory." - }, "sqlfluff.executablePath": { "type": "string", "default": "sqlfluff", @@ -244,6 +202,44 @@ ], "markdownDescription": "Set the rules that will not show the `noqa` code actions. Set this to `false` to disable all `noqa` code actions." }, + "sqlfluff.env.environmentVariables": { + "type": "array", + "default": [ + { + "key": "EXAMPLE_KEY", + "value": "example_value" + } + ], + "items": { + "type": "object", + "additionalProperties": false, + "required": [ + "key", + "value" + ], + "properties": { + "key": { + "type": "string", + "markdownDescription": "The key for the environment variable." + }, + "value": { + "type": "string", + "markdownDescription": "The value for the environment variable." + } + } + }, + "markdownDescription": "Set the environment variables for the linter and formatter." + }, + "sqlfluff.env.customDotEnvFiles": { + "type": "array", + "default": [], + "description": "Load the .env file from the specified paths." + }, + "sqlfluff.env.useDotEnvFile": { + "type": "boolean", + "default": false, + "description": "Load the .env file from the working directory." + }, "sqlfluff.format.arguments": { "type": "array", "default": [], @@ -254,6 +250,17 @@ "default": true, "description": "Determines if the document formatter is enabled." }, + "sqlfluff.format.languages": { + "type": "array", + "default": [ + "sql", + "sql-bigquery", + "jinja-sql", + "postgres", + "snowflake-sql" + ], + "description": "The languages formatting is enabled for." + }, "sqlfluff.experimental.format.executeInTerminal": { "type": "boolean", "default": false, @@ -314,6 +321,17 @@ "default": false, "markdownDescription": "Determines if the linter will lint the workspaces on startup and configuration changes. Does not work with `dbt-osmosis`." }, + "sqlfluff.linter.languages": { + "type": "array", + "default": [ + "sql", + "sql-bigquery", + "jinja-sql", + "postgres", + "snowflake-sql" + ], + "description": "The languages linting is enabled for." + }, "sqlfluff.linter.run": { "type": "string", "enum": [ diff --git a/src/extension.ts b/src/extension.ts index e0b25af..157bb14 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -16,9 +16,10 @@ export const activate = (context: vscode.ExtensionContext) => { const linterProvider = new LinterProvider(); const lintingProvider = linterProvider.activate(context.subscriptions); - const selectors = ["sql", "sql-bigquery", "jinja-sql", "postgres", "snowflake-sql"]; + const formatSelectors = Configuration.formatLanguages(); + const linterSelectors = Configuration.linterLanguages(); - selectors.forEach(selector => { + formatSelectors.forEach(selector => { // Register the "Format Document" command const formattingProvider = new FormattingEditProvider().activate(); vscode.languages.registerDocumentFormattingEditProvider( @@ -34,7 +35,9 @@ export const activate = (context: vscode.ExtensionContext) => { rangeFormattingProvider, ); } + }); + linterSelectors.forEach(selector => { // Register the code actions if (!Configuration.osmosisEnabled()) { const codeActionProvider = vscode.languages.registerCodeActionsProvider(selector, new QuickFixProvider(), { @@ -43,6 +46,7 @@ export const activate = (context: vscode.ExtensionContext) => { context.subscriptions.push(codeActionProvider); } + // Register the hover provider const hoverProvider = vscode.languages.registerHoverProvider(selector, new HoverProvider()); context.subscriptions.push(hoverProvider); }); diff --git a/src/features/helper/configuration.ts b/src/features/helper/configuration.ts index ff9fa90..35cfbd4 100644 --- a/src/features/helper/configuration.ts +++ b/src/features/helper/configuration.ts @@ -9,14 +9,13 @@ import RunTrigger from "./types/runTrigger"; import Variables from "./types/variables"; import Utilities from "./utilities"; -export const filePattern = "**/*.{sql,sql-bigquery,jinja-sql,postgres|snowflake-sql}"; -export const fileRegex = /^.*\.(sql|sql-bigquery|jinja-sql|postgres|snowflake-sql)$/; - export default class Configuration { /** Initialize the configuration options that require a reload upon change. */ static initialize(): void { vscode.workspace.onDidChangeConfiguration((event) => { if ( + event.affectsConfiguration("sqlfluff.format.languages") || + event.affectsConfiguration("sqlfluff.linter.languages") || event.affectsConfiguration("sqlfluff.osmosis.enabled") || event.affectsConfiguration("sqlfluff.experimental.format.executeInTerminal") ) { @@ -192,8 +191,7 @@ export default class Configuration { return workingDirectory ? workingDirectory : rootPath; } - /* Code Actions */ - + // #region Code Actions public static excludeRulesWorkspace(): boolean { return vscode.workspace .getConfiguration("sqlfluff.codeActions.excludeRules") @@ -225,22 +223,31 @@ export default class Configuration { return noqa; } + // #endregion - /* Format */ - + // #region Format public static formatEnabled(): boolean { return vscode.workspace .getConfiguration("sqlfluff.format") .get("enabled", true); } + public static formatLanguages(): string[] { + const languages: any = vscode.workspace + .getConfiguration("sqlfluff.format") + .get("languages"); + + return languages; + } + public static executeInTerminal(): boolean { return vscode.workspace .getConfiguration("sqlfluff.experimental.format") .get("executeInTerminal", false); } + // #endregion - /* Linter */ + // #region Linter public static delay(): number { return vscode.workspace .getConfiguration("sqlfluff.linter") @@ -301,14 +308,22 @@ export default class Configuration { .get("lintEntireProject", false); } + public static linterLanguages(): string[] { + const languages: any = vscode.workspace + .getConfiguration("sqlfluff.linter") + .get("languages"); + + return languages; + } + public static runTrigger(): string { return vscode.workspace .getConfiguration("sqlfluff.linter") .get("run", RunTrigger.onType); } + // #endregion - /* Arguments */ - + // #region Arguments public static lintFileArguments(): string[] { const extraArguments = [...this.lintArguments(), "--format", "json"]; @@ -333,9 +348,9 @@ export default class Configuration { return extraArguments; } + // #endregion - /* Osmosis */ - + // #region Osmosis public static osmosisEnabled(): boolean { return vscode.workspace .getConfiguration("sqlfluff.osmosis") @@ -353,6 +368,7 @@ export default class Configuration { .getConfiguration("sqlfluff.osmosis") .get("port", 8581); } + // #endregion /** * @returns The variables for a terminal diff --git a/src/features/linter.ts b/src/features/linter.ts index 099911d..840809e 100644 --- a/src/features/linter.ts +++ b/src/features/linter.ts @@ -12,7 +12,7 @@ import Linter from "./providers/linter/types/linter"; import Violation from "./providers/linter/types/violation"; export default class LinterProvider implements Linter { - public languageId = ["sql", "jinja-sql", "sql-bigquery", "postgres", "snowflake-sql"]; + public languageId = Configuration.linterLanguages(); public activate(subscriptions: Disposable[]): LintingProvider { const provider = new LintingProvider(this); diff --git a/test/.vscode/settings.json b/test/.vscode/settings.json index e3e964d..86c67be 100644 --- a/test/.vscode/settings.json +++ b/test/.vscode/settings.json @@ -6,14 +6,22 @@ "sqlfluff.codeActions.excludeRules.workspace": false, "sqlfluff.config": "${workspaceFolder}/.sqlfluff", "sqlfluff.dialect": "postgres", + "sqlfluff.format.languages": [ + "sql", + "sql-bigquery", + "jinja-sql", + "postgres", + "snowflake-sql", + "markdown" + ], /* Linter */ "sqlfluff.linter.delay": 500, "sqlfluff.linter.run": "onType", - "sqlfluff.linter.lintEntireProject": true, + "sqlfluff.linter.lintEntireProject": false, "sqlfluff.rules": [], "sqlfluff.ignoreParsing": false, - "sqlfluff.suppressNotifications": false, + "sqlfluff.suppressNotifications": true, /* Formatter */ "sqlfluff.format.enabled": true, "sqlfluff.experimental.format.executeInTerminal": false, diff --git a/test/suite/test_sql/markdown.md b/test/suite/test_sql/markdown.md new file mode 100644 index 0000000..2909fea --- /dev/null +++ b/test/suite/test_sql/markdown.md @@ -0,0 +1,21 @@ +## SQL to be formated + +``` sql +SELECT * +from EMP +JOIN DEPT ON EMP.DEPTNO = DEPT.DEPTNO; +``` + +## SQL to be ignored + +``` +SELECT * FROM EMP JOIN DEPT ON EMP.DEPTNO = DEPT.DEPTNO; +``` + +## JavaScript to be ignored + +``` js +var foo = function (bar) { + return bar++; +}; +```