Skip to content

Commit

Permalink
v2.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertOstermann committed Jul 15, 2023
1 parent 437f26f commit 4b74c2b
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 61 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.

## [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`
Expand Down
106 changes: 62 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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": [],
Expand All @@ -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,
Expand Down Expand Up @@ -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": [
Expand Down
8 changes: 6 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(), {
Expand All @@ -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);
});
Expand Down
40 changes: 28 additions & 12 deletions src/features/helper/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
) {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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<boolean>("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<boolean>("executeInTerminal", false);
}
// #endregion

/* Linter */
// #region Linter
public static delay(): number {
return vscode.workspace
.getConfiguration("sqlfluff.linter")
Expand Down Expand Up @@ -301,14 +308,22 @@ export default class Configuration {
.get<boolean>("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<string>("run", RunTrigger.onType);
}
// #endregion

/* Arguments */

// #region Arguments
public static lintFileArguments(): string[] {
const extraArguments = [...this.lintArguments(), "--format", "json"];

Expand All @@ -333,9 +348,9 @@ export default class Configuration {

return extraArguments;
}
// #endregion

/* Osmosis */

// #region Osmosis
public static osmosisEnabled(): boolean {
return vscode.workspace
.getConfiguration("sqlfluff.osmosis")
Expand All @@ -353,6 +368,7 @@ export default class Configuration {
.getConfiguration("sqlfluff.osmosis")
.get<number>("port", 8581);
}
// #endregion

/**
* @returns The variables for a terminal
Expand Down
2 changes: 1 addition & 1 deletion src/features/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 10 additions & 2 deletions test/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions test/suite/test_sql/markdown.md
Original file line number Diff line number Diff line change
@@ -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++;
};
```

0 comments on commit 4b74c2b

Please sign in to comment.