Giter Club home page Giter Club logo

sql-language-server's Introduction

SQL Language Server

build-and-test

The SQL Language Server offers autocompletion, error/warning notifications, and other editor support. It includes a linting feature, an SQL parser, and a Visual Studio Code extension. It supports MySQL, PostgreSQL, and SQLite3 databases.

completion

Packages

Supported DB

  • MySQL
  • PostgreSQL
  • SQLite3

Installation & How to setup

Visual Studio Code

Install the VSC extension.

Other Editors

npm i -g sql-language-server

Neovim

Add the following to the init.vim file (.vimrc):

let g:LanguageClient_serverCommands = {
    \ 'sql': ['sql-language-server', 'up', '--method', 'stdio'],
    \ }

Run the following command and reference the nvim-lsp documentation for more information.

:LspInstall sqlls

Monaco Editor (monaco-languageclient)

See the example to use the Monaco Editor to develop sql-language-server.

Follow the development section section to check Mocaco Editor working.

Usage

CLI

$ sql-language-server up [options]        run sql-language-server

Options

  --version      Show version number                                   [boolean]
  --help         Show help                                             [boolean]
  --method, -m  What use to communicate with sql language server
                   [string] [choices: "stdio", "node-ipc"] [default: "node-ipc"]
  --debug, -d    Enable debug logging                 [boolean] [default: false]
  • Example
$ sql-language-server up --method stdio

Configuration

There are two ways to use configuration files.

  • Set personal configuration file (~/.config/sql-language-server/.sqllsrc.json)
  • Set project configuration file on your project root (${YOUR_PROJECT}/.sqllsrc.json)
  • Use workspace/configuration according to LSP specification

Example for personal configuration file

  • Examples
{
  "connections": [
    {
      "name": "sql-language-server",
      "adapter": "mysql",
      "host": "localhost",
      "port": 3307,
      "user": "username",
      "password": "password",
      "database": "mysql-development",
      "projectPaths": ["/Users/joe-re/src/sql-language-server"],
      "ssh": {
        "user": "ubuntu",
        "remoteHost": "ec2-xxx-xxx-xxx-xxx.ap-southeast-1.compute.amazonaws.com",
        "dbHost": "127.0.0.1",
        "port": 3306,
        "identityFile": "~/.ssh/id_rsa",
        "passphrase": "123456"
      }
    },
    {
      "name": "postgres-project",
      "adapter": "postgres",
      "host": "localhost",
      "port": 5432,
      "user": "postgres",
      "password": "pg_pass",
      "database": "pg_test",
      "projectPaths": ["/Users/joe-re/src/postgres_project"]
    },
    {
      "name": "sqlite3-project",
      "adapter": "sqlite3",
      "filename": "/Users/joe-re/src/sql-language-server/packages/server/test.sqlite3",
      "projectPaths": ["/Users/joe-re/src/sqlite2_project"]
    }
  ]
}

Please restart sql-language-server process after creating .sqllsrc.json.

Connection parameters

Key Description value required default
name Connection name(free-form text) true
adapter Database type "mysql" or "postgres" or "sqlite3" or "bigquery" true
host Database host string false
port Database port string false mysql:3306, postgres:5432
user Database user string false mysql:"root", postgres:"postgres"
password Database password string false
database Database name string false
filename Database filename(only for sqlite3) string false
projectPaths Project path that you want to apply(if you don't set it configuration will not apply automatically when lsp's started up) string[] false []
ssh Settings for port fowarding *see below SSH section false
SSH
Key Description value required default
remoteHost The host address you want to connect to string true
remotePort Port number of the server for ssh number false 22
user User name on the server string false
dbHost Database host on the server string false 127.0.0.1
dbPort Database port on the server number false mysql:3306, postgres:5432
identityFile Identity file for ssh string false ~/.ssh/config/id_rsa
passphrase Passphrase to allow to use identity file string false

Personal configuration file

The personal configuration file is located at ~/.config/sql-language-server/.sqllsrc.json. When the SQL Language Server starts, it will try to read this file.

Project configuration file

The project configuration file is located at ${YOUR_PROJECT_ROOT}/.sqllsrc.json. This file has the same settings as the personal configuration file, with a few exceptions:

  • The connection property is specified directly, rather than as an array.
  • The project path does not need to be set. If it is set, it will be ignored.
  • The project configuration file is merged with the personal configuration file, if it exists.

Here is an example project configuration file for a PostgreSQL database:

{
  "name": "postgres-project",
  "adapter": "postgres",
  "host": "localhost",
  "port": 5432,
  "user": "postgres",
  "database": "pg_test"
}

If you have also set a personal configuration, the project configuration and personal configure will be merged if they have the same name.

Personal configuration example:

{
  "connections": [{
    "name": "postgres-project",
    "password": "password",
    "ssh": {
      "user": "ubuntu",
      "remoteHost": "ec2-xxx-xxx-xxx-xxx.ap-southeast-1.compute.amazonaws.com",
      "dbHost": "127.0.0.1",
      "port": 5432,
      "identityFile": "~/.ssh/id_rsa",
      "passphrase": "123456"
    }
  }]
}

It will merge them as follows:

{
  "name": "postgres-project",
  "adapter": "postgres",
  "host": "localhost",
  "port": 5432,
  "user": "postgres",
  "database": "pg_test",
  "password": "password",
  "ssh": {
    "user": "ubuntu",
    "remoteHost": "ec2-xxx-xxx-xxx-xxx.ap-southeast-1.compute.amazonaws.com",
    "dbHost": "127.0.0.1",
    "port": 5432,
    "identityFile": "~/.ssh/id_rsa",
    "passphrase": "123456"
  }
}

Workspace configuration for sql-language-server

Parameters of workspace configuration
  • connections: This parameter is the same as the connections parameter in the personal configuration file. It allows you to specify the connections for your workspace.
  • lint: This parameter is the same as the configuration of sqlint. It allows you to configure the linting rules for your workspace.
Example of workspace configuration

~/.config/nvim/coc-settings.json

{
  "languageserver": {
    "sql": {
      "command": "sql-language-server",
      "args": ["up", "--method", "stdio"],
      "filetypes": ["sql"],
      "settings": {
        "sqlLanguageServer": {
          "connections": [
            {
              "name": "mysql_project",
              "adapter": "mysql",
              "host": "127.0.0.1",
              "port": 3306,
              "user": "sqlls",
              "password": "sqlls",
              "database": "mysql_db",
              "projectPaths": ["/Users/joe_re/src/MysqlProject"],
              "ssh": {
                "user": "ubuntu",
                "remoteHost": "xxx-xx-xxx-xxx-xxx.ap-southeast-1.compute.amazonaws.com",
                "dbHost": "127.0.0.1",
                "port": 3306
              }
            }
          ],
          "lint": {
            "rules": {
              "align-column-to-the-first": "error",
              "column-new-line": "error",
              "linebreak-after-clause-keyword": "off",
              "reserved-word-case": ["error", "upper"],
              "space-surrounding-operators": "error",
              "where-clause-new-line": "error",
              "align-where-clause-to-the-first": "error"
            }
          }
        }
      }
    }
  }
}
  • VS Code workspace setting
"settings": {
  "sqlLanguageServer.connections": [
    {
      "name": "mysql_project",
      "adapter": "mysql",
      "host": "127.0.0.1",
      "port": 3306,
      "user": "sqlls",
      "password": "sqlls",
      "database": "mysql_db",
      "projectPaths": ["/Users/joe_re/src/MysqlProject"],
      "ssh": {
        "user": "ubuntu",
        "remoteHost": "xxx-xx-xxx-xxx-xxx.ap-southeast-1.compute.amazonaws.com",
        "dbHost": "127.0.0.1",
        "port": 3306
      }
    }
  ],
  "sqlLanguageServer.lint": {
    "rules": {
      "align-column-to-the-first": "off",
      "column-new-line": "error",
      "linebreak-after-clause-keyword": "error",
      "reserved-word-case": ["error", "upper"],
      "space-surrounding-operators": "error",
      "where-clause-new-line": "error",
      "align-where-clause-to-the-first": "error",
    }
  }
}

Inject environment variables

${env:VARIABLE_NAME} syntax allows you to replace configuration value with an environment variable. This is useful if you don't want to store the value in the configuration file.

Example
{
  "adapter": "mysql",
  "host": "localhost",
  "port": 3307,
  "user": "username",
  "password": "${env:DB_PASSWORD}",
  "database": "mysql-development",
  "ssh": {
    "user": "ubuntu",
    "remoteHost": "ec2-xxx-xxx-xxx-xxx.ap-southeast-1.compute.amazonaws.com",
    "dbHost": "127.0.0.1",
    "port": 3306,
    "identityFile": "~/.ssh/id_rsa",
    "passphrase": "${env:SSH_PASSPHRASE}"
  }
}

Switch database connection

If you have multiple connection entries in your personal config file, you can switch the database connection.

2020-05-25_15-23-01

VSC extension provides Switch database connection command.

Raw RPC param:

method: workspace/executeCommand
command: switchDataBaseConnection
arguments: string(project name)

SQLite3 Notes

If you get error when you use sqlite3 connection, you may need to rebuild sqlite3 to your environment.

VSC extension provides the command to rebuild it.(Name: Rebuild SQLite3 Client) image

If you're using sql-language-server directly, go to the install directory and run npm rebuild sqlite to rebuild it.

Linting

You can use lint rules provided by sqlint to ensure your SQL code follows best practices and avoid potential errors. Refer to the sqlint configuraton documentation to learn how to use and configure the linter to match your use case.

sqlint-on-editor

You can also use sqlint to automatically fix any problems it can identify in your code.

2020-06-18_08-24-03

Raw RPC param:

method: workspace/executeCommand
command: fixAllFixableProblems
arguments: string(document uri)

Contributing to sql-language-server

Bug Reports and Feature Requests

If you have any questions, problems or suggestions for improvements, feel free to create a new issue on GitHub Issues. You can also start a discussion there about new rules for SQLint.

Development

Code contributions are always appreciated, so feel free to fork the repo and submit pull requests.

Development environment

You can start developing sql-language-server using Docker Compose. To begin the development process in your Docker container, run the following command:

$ docker compose up

Open http://localhost:3000 on your browser.

Migrating the Database

To migrate the database, follow these steps:

  1. Login into development Docker container
$ docker compose exec assets bash
  1. Migrate the database
$ cd example/monaco_editor
$ yarn migrate:postgres # postgres
$ yarn migrate:mysql    # mysql
$ yarn migrate:sqlite   # sqlite3

sql-language-server's People

Contributors

adrianlzt avatar astridlyre avatar auchenberg avatar cccs-jc avatar dependabot[bot] avatar hsuanxyz avatar joe-re avatar krassowski avatar leko avatar maixiu avatar r6eve avatar ravilock avatar timabdulla avatar tkolleh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sql-language-server's Issues

Debug Instructions

Hey @joe-re

I'm trying to debug the sql-language-server extension inside VSCode. I see there are 2 launch configurations. One for the VSCode client and one to attach to the sql-language-server node process on port 6009.

I'm able to attach to the server on port 6009 however I can't set breakpoints inside the .ts files. The breakpoints are "unbound".

Wondering how I could step through the sql-language-server code in this setup. Any suggestions?

Error occur when installing via npm

I install sql-language-server using command npm i -g sql-language-server in order to use in neovim with coc.nvim.

There are some error occur:

npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated [email protected]: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future
npm ERR! code 1
npm ERR! path /home/shizuku/.volta/tmp/image/packages/.tmpO7NgTt/lib/node_modules/sql-language-server/node_modules/sqlite3
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | linux | x64
npm ERR! gyp info find Python using Python version 3.9.7 found at "/usr/bin/python3"
npm ERR! (node:13958) [DEP0150] DeprecationWarning: Setting process.config is deprecated. In the future the property will be read-only.
npm ERR! (Use `node --trace-deprecation ...` to show where the warning was created)
npm ERR! gyp info spawn /usr/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/home/shizuku/.volta/tools/image/npm/7.24.1/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/home/shizuku/.volta/tmp/image/packages/.tmpO7NgTt/lib/node_modules/sql-language-server/node_modules/sqlite3/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/home/shizuku/.volta/tools/image/npm/7.24.1/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/home/shizuku/.cache/node-gyp/16.9.0/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/home/shizuku/.cache/node-gyp/16.9.0',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/home/shizuku/.volta/tools/image/npm/7.24.1/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/home/shizuku/.cache/node-gyp/16.9.0/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/home/shizuku/.volta/tmp/image/packages/.tmpO7NgTt/lib/node_modules/sql-language-server/node_modules/sqlite3',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp: Undefined variable module_name in binding.gyp while trying to load binding.gyp
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
npm ERR! gyp ERR! stack     at ChildProcess.onCpExit (/home/shizuku/.volta/tools/image/npm/7.24.1/node_modules/node-gyp/lib/configure.js:351:16)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:394:28)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
npm ERR! gyp ERR! System Linux 5.14.9-arch2-1
npm ERR! gyp ERR! command "/home/shizuku/.volta/tools/image/node/16.9.0/bin/node" "/home/shizuku/.volta/tools/image/npm/7.24.1/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /home/shizuku/.volta/tmp/image/packages/.tmpO7NgTt/lib/node_modules/sql-language-server/node_modules/sqlite3
npm ERR! gyp ERR! node -v v16.9.0
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/shizuku/.npm/_logs/2021-10-11T03_29_03_943Z-debug.log

os: Archlinux
node: 16.9.0 (from volta)
npm: 7.24.1

Issue with running Monaco example with docker connection

Hey, I was trying to run both the monaco example and docker to have the db connection but I don't seem to get it work.
I tried to run:

  1. yarn install
  2. docker-compose up
  3. yarn && yarn dev

And also:

  1. yarn install
  2. yarn && yarn dev
  3. docker-compose up

However I see both docker and the editor are trying to connect to port 3000 and that gives me an error. I tried to change the port number but when I do, it doesn't show up the databases on monaco.

I also tried to just run docker-compose up and connect to localhost:3000 but the page doesn't load.

Is there any step that I am missing?

Unable to change configuration when using JupyterLab

I've installed sql-language-server and I'm able to use it both in VSCode and in JupyterLab.

In both environment I'm able to see the diagnostic errors and the completion of keywords such as SELECT, FROM, WHERE.

However in JupyterLab I'm not able or don't know how to configure sql-language-server to connect to a sqlite3 sample database in order to benefit from the completion of the table/column names.

Is there a way to do this? I've tried putting configuration inside the jupyterlab advanced settings @krassowski/jupyterlab-lsp:plugin. I've also tried inside ~/.config but no luck..

[SQLint] add lint rule always using AS to rename columns

Good:

SELECT
  employees.name AS employee_name,
  COUNT(tasks.id) AS assigned_task_count
FROM
  employees LEFT JOIN tasks
    ON employees.id = tasks.id

Bad:

SELECT
  employees.name employee_name,
  COUNT(tasks.id) assigned_task_count
FROM
  employees LEFT JOIN tasks
    ON employees.id = tasks.id

upgrade sqlite

when I install sql-language-server with a recent version of node I get the following error

Pre-built binaries not found for [email protected] and [email protected]

Would using sqlite3 version 5.0.1 fix that. Is it okay to upgrade it.

Add BigQuery to supported DBs?

Has anyone thought about extending this language server to support BigQuery as well?

I've looking into how I might develop a language server for BQ, and I stumbled upon this repo. Would it be simpler to develop my own from scratch or simply extend this one?

Help!

How to fix this problem??!!

image

postgresql meta syntax support

Thank you for the ls for sql. Is there a way to have the linter ignore lines that include postgresql meta?

For instance, the first line in the following:

\set obj_name 'sharing_queue_on_update_trigger'

create or replace function :obj_name()
returns trigger as $$
    begin
        ...
    end;
$$ language plpgsql;

'A linebreak is required...' lint error incorrectly showing with nvim lsp

Using this with nightly neovim and the completion-nvim plugin. I get this lint error for every keyword regardless of whether there is a new line or not.

Screen Shot 2020-09-30 at 6 54 17 PM

I have the following in my init.vim:

lua <<EOF

local nvim_lsp = require'nvim_lsp'

local on_attach = function(client)
    require'completion'.on_attach(client)
    require'diagnostic'.on_attach(client)
end

nvim_lsp.sqlls.setup({ on_attach=on_attach })

EOF



let g:LanguageClient_serverCommands = {
    \ 'sql': ['sql-language-server', 'up', '--method', 'stdio'],
    \ }

Use pg_query for parsing instead of peg.js

Have you ever heard/seen/read of pg_query (2.0)? Thereโ€™s a npm module (psql-parser) that allows it to be used, and it might be a good fit instead of the parser generated by peg.js this library uses.

I would think that it would allow for more easier support of certain statements, and maybe procedures/functions/routines.

It's not a typescript lib, so the typings are a bit missing, but I found this gist that's at least defined a good amount already. From the looks of it, it should at least provide similar if not more functionality than the parser currently used. (CTE aka WITH for example)

Support VSCodium

That is all I get when trying to use this in VSCodium. I did create a .sqllsrc.json file in my project root. I also tried creating a personal config file as well, but that didn't change anything.

Message: Request textDocument/completion failed with message: Cannot read property 'start' of undefined

VSCode Version: 1.44.2

I open .sql file ๏ผŒinput words ๏ผŒthen OUTPUT throw error

[0514/143718.898943:ERROR:node_debugger.cc(50)] Error parsing node options: [DEP0062]: `node --debug` and `node --debug-brk` are invalid. Please use `node --inspect` and `node --inspect-brk` instead.
start sql-language-server
start sql-language-server
[Error - 2:37:25 PM] Request textDocument/completion failed.
  Message: Request textDocument/completion failed with message: Cannot read property 'start' of undefined
  Code: -32603 

sqlint exception

The same .sqlintrc.json content both in project folder and personal folder as:
{
"rules": {
"align-column-to-the-first": 0,
"column-new-line": 0,
"linebreak-after-clause-keyword": 0,
"reserved-word-case": [0,"upper"],
"space-surrounding-operators": 0,
"where-clause-new-line": 0
}
}

It's a bit of wired that this error only appears twice.

Error: No files matching 'undefined' were found.
at lint (/home/xxxx/.vscode/extensions/joe-re.sql-language-server-0.10.7/packages/server/dist/cli.js:69491:15)
at doLint (/home/xxxx/.vscode/extensions/joe-re.sql-language-server-0.10.7/packages/server/dist/cli.js:69557:31)
at createDiagnostics (/home/xxxx/.vscode/extensions/joe-re.sql-language-server-0.10.7/packages/server/dist/cli.js:69583:23)
at /home/xxxx/.vscode/extensions/joe-re.sql-language-server-0.10.7/packages/server/dist/cli.js:106849:29
at CallbackList.invoke (/home/xxxx/.vscode/extensions/joe-re.sql-language-server-0.10.7/packages/server/dist/cli.js:9282:39)
at Emitter.fire (/home/xxxx/.vscode/extensions/joe-re.sql-language-server-0.10.7/packages/server/dist/cli.js:9341:36)
at /home/xxxx/.vscode/extensions/joe-re.sql-language-server-0.10.7/packages/server/dist/cli.js:15155:38
at handleNotification (/home/xxxx/.vscode/extensions/joe-re.sql-language-server-0.10.7/packages/server/dist/cli.js:10765:43)
at processMessageQueue (/home/xxxx/.vscode/extensions/joe-re.sql-language-server-0.10.7/packages/server/dist/cli.js:10536:17)
at Immediate._onImmediate (/home/xxxx/.vscode/extensions/joe-re.sql-language-server-0.10.7/packages/server/dist/cli.js:10523:13)

LSP diagnotiscs work fine after this error
image

Proposal to support json adapter

sql-language-server currently supports 3 types of adapters

  • MySQL
  • PostgreSQL
  • SQLite3

In this fork I have implemented a forth adapter named json. The idea is to load a schema from an external file. For platform like spark this is very useful because users can create tables in their own spark environment. Also it is difficult to configure the spark driver in sql-language-server the same way it's configured in the user's jupyterlab notebooks.

@joe-re Have a look at the following documentation. If you like the idea of an external json adapter and the integration with JupyterLab I will spend more time on these features and make proper PR to your repository. I believe it would best for the community to incorporate this work into your code base.

https://github.com/cccs-jc/sql-language-server/tree/develop/example/jupyterlab

Let me know what you think. Looking forward to collaborate.
Cheers
jc

Question about personal configuration file support

hey @joe-re when I run sql-language-server within jupyterlab-lsp I configure initialize 2 sql-language-server. One for sparksql and one for trino

c.LanguageServerManager.language_servers = {
   "sparksql-language-server": {
        "argv": [mgr.nodejs, node_module_path, *args],
        "languages": ["sparksql"],
        "version": 2,
        "mime_types": ["text/x-sparksql"],
        "display_name": "Spark language server",
        "config_schema": load_config_schema(key),
    },
   "trino-language-server": {
        "argv": [mgr.nodejs, node_module_path, *args],
        "languages": ["trino"],
        "version": 2,
        "mime_types": ["text/x-trino"],
        "display_name": "Trino language server",
        "config_schema": load_config_schema(key),
    }
}

I do that because in jupyterlab I have no means to switch between connections and nor would I want to. That is when I select a %%sparksql cell its mime type is `text/x-sparksql` and thus uses the first sql-language-server instance. When editing a %%trino cell it uses the other instance. So this is quite convenient for a user. There is no need to manually switch between connections.

However a user has to configure the sql-language-lsp via the advanced properties


```json
{
    "@krassowski/jupyterlab-lsp:syntax_highlighting": {
        "foreignCodeThreshold": 0.99
    },
    "@krassowski/jupyterlab-lsp:plugin": {
        "logAllCommunication": true,
        "loggingLevel": "debug",
        "setTrace": "verbose",
        "language_servers": {
            "sparksql-language-server": {
                "serverSettings": {
                    "sqlLanguageServer": {
                        "connections": [
                            {
                                "name": "pyspark-conf",
                                "adapter": "json",
                                "filename": "/tmp/sparkdb.schema.json",
                                "jupyterLabMode": true
                            }
                        ]
                    }
                }
            },
            "trino-language-server": {
                "serverSettings": {
                    "sqlLanguageServer": {
                        "connections": [
                            {
                                "name": "trino-conf",
                                "adapter": "json",
                                "filename": "/tmp/trinodb.schema.json",
                                "jupyterLabMode": true
                            }
                        ]
                    }
                }
            }
        }
    }
}

I think you have a means for the user to provide a personal configuration file. .sqlsrc.json

is there a way to provide the location of this file. I would like my jupyterlab extension to provide a default .sqlsrc.json file.

Also if the user then sets up configuration via the advanced settings (thus via the LSP protocol). Does it take precedence over the .sqlsrc.json file. Ideally I'd provide default settings via the .sqlsrc.json file and let the user override these settings in the connection configuration.

Does that make sense. How far are we from having it work this way?

Issue building vscode extension

@joe-re In my pull request you will see that I've added a dependency on CompletionTriggerKind.

I can build the server and test it with JupyterLab no problem using this build command

sql-language-server/packages/server$ npm run prepublish

I would now like to build it for vscode using this command.

sql-language-server/packages/server$ npm run prepare-vsc-extension

However I get this error

[!] Error: 'CompletionTriggerKind' is not exported by node_modules/vscode-languageserver/node.js, imported by src/createServer.ts
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
src/createServer.ts (1:9)
1: import { CompletionTriggerKind, } from 'vscode-languageserver/node';
            ^
2: import * as VscodeNode from 'vscode-languageserver/node';
3: import { TextDocument } from 'vscode-languageserver-textdocument';
Error: 'CompletionTriggerKind' is not exported by node_modules/vscode-languageserver/node.js, imported by src/createServer.ts
    at error (/Users/jc/jupyter-ext/sql-language-server/packages/server/node_modules/rollup/dist/shared/rollup.js:151:30)
    at Module.error (/Users/jc/jupyter-ext/sql-language-server/packages/server/node_modules/rollup/dist/shared/rollup.js:10059:16)
    at Module.traceVariable (/Users/jc/jupyter-ext/sql-language-server/packages/server/node_modules/rollup/dist/shared/rollup.js:10444:29)
    at ModuleScope.findVariable (/Users/jc/jupyter-ext/sql-language-server/packages/server/node_modules/rollup/dist/shared/rollup.js:9227:39)
    at FunctionScope.findVariable (/Users/jc/jupyter-ext/sql-language-server/packages/server/node_modules/rollup/dist/shared/rollup.js:3654:38)
    at ChildScope.findVariable (/Users/jc/jupyter-ext/sql-language-server/packages/server/node_modules/rollup/dist/shared/rollup.js

I'm not familiar with what rollup does but I suspect the issue might be with that script. Any help would be much appreciated. Thanks

Help - Adding Oracle support

I have beyond zero experience with JS-flavor languages, but am interested in adding Oracle support. Would the best place to base my ventures off of be something like this commit (which added BigQuery)?

Any other general advice in this respect?

Add some documentation?

Hi there!

Could you please add some docs on how to install/use this project and the status of the project, so that we can kick the tires?

Thanks!

Unable to configure development environment

For the past few days, I've been trying to get a development environment up and running on my local machine, but I can't quite seem to get it working. After cloning the repo, and ensuring that Docker is properly installed, I receive the following error.

ssets_1    | /bin/sh: 1: run-p: not found
assets_1    | error Command failed with exit code 127.
assets_1    | info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I then tried installing run-p with npm install run-p, but this only leads my down an endless rabbit hole of installing npm packages, and npm install doesn't help. Eventually, I receive issues with the webpack.config.js file included in the example, so I assume this is happening because of a bit of setup that I'm missing?

Your VS Code extension is affected by event stream and have been blocked

Hi,

Kenneth here from the VS Code team.

Your extension is affected by https://code.visualstudio.com/blogs/2018/11/26/event-stream, and we have blocked your extension.

In order to enable your extension again the workflow is:

  1. Fix the extension, submit an update to the marketplace
  2. Send mail to [email protected] and [email protected] and notify us.
  3. We will verify that the extension is okay
  4. Our marketplace will publish the extension again and we'll remove the extension from the blocklist

troubleshooting?

Hi, this extension does not appear to be working at all for me. I've configured a connection, and see it when I try and change connection, but when I edit an sql file I get no autocomplete. Any suggestions for how to troubleshoot this?

Complete outer query not working

Given the following statement ctrl-space at char 8th, to complete the alias fails

SELECT t FROM (SELECT col1 FROM table1 as tab)

The error is

[2022-02-06] [DEBUG] default - TypeError: Cannot read properties of null (reading 'startsWith')
at Identifier.matchesLastToken (/opt/conda/lib/node_modules/sql-language-server/dist/src/complete.js:50:29)
at /opt/conda/lib/node_modules/sql-language-server/dist/src/complete.js:289:34
at Array.filter ()
at Completer.addCandidatesForTables (/opt/conda/lib/node_modules/sql-language-server/dist/src/complete.js:289:14)
at Completer.addCandidatesForParsedSelectQuery (/opt/conda/lib/node_modules/sql-language-server/dist/src/complete.js:485:22)
at Completer.addCandidatesForParsedStatement (/opt/conda/lib/node_modules/sql-language-server/dist/src/complete.js:502:18)
at Completer.complete (/opt/conda/lib/node_modules/sql-language-server/dist/src/complete.js:148:18)
at complete (/opt/conda/lib/node_modules/sql-language-server/dist/src/complete.js:656:34)
at /opt/conda/lib/node_modules/sql-language-server/dist/src/createServer.js:206:52
at /opt/conda/lib/node_modules/sql-language-server/node_modules/vscode-languageserver/lib/common/server.js:678:20

Problem running in nvim_lsp

Hi,
I'm trying to use your language server with the native nvim_lsp client. I have set the configuration according to nvim-lspconfig and have a project .sqllsrc.json in my project directory. The project uses PostgreSQL. As far as I can tell is the server being started, the log looks like this:

[2020-09-24T21:31:36.687] [INFO] default - start sql-languager-server
[2020-09-24T21:31:36.708] [DEBUG] default - onInitialize: /home/user/projects/metis-backend
[2020-09-24T21:31:36.726] [DEBUG] default - onDidChangeContent: file:///home/user/projects/project/sql/migrations/00001_initial_schema.sql, 0
[2020-09-24T21:31:36.732] [DEBUG] default - There isn't personal config file. /home/user/.config/sql-language-server/.sqllsrc.json
[2020-09-24T21:31:36.733] [DEBUG] default - Set config: {"name":"project-pg","adapter":"postgres","host":"localhost","password":"password","database":"db","ssh":{}}
[2020-09-24T21:31:36.734] [DEBUG] default - setting store, emit "change"
[2020-09-24T21:31:36.734] [DEBUG] default - onInitialize: receive change event from SettingStore
[2020-09-24T21:31:36.739] [DEBUG] default - createDiagnostics
[2020-09-24T21:31:36.746] [DEBUG] default - parse error
[2020-09-24T21:31:36.747] [DEBUG] default - peg$SyntaxError: Expected "$", "(", "--", "/*", "DELETE", "INSERT", "REPLACE", "SELECT", "UPDATE", "return", or [ \t\n\r] but "C" found

My file starts like this:

-- Extensions
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS citext;

This is valid code for PostgreSQL so do you have an idea where this error comes from or what I might have done wrong in my configuration? The database it tries to connect to is running and the adapter seems to be picked up correctly, if I change it to mysql or when I change the password the log lists a connection error.

I'm grateful for any pointers.
Regards,
Daniel

cmd not defined with neovim LSP

I installed with LspInstall and things seem to detect correctly with server starting up okay and everthing. However, I'm seeing cmd not defined error whenever I was doing :LspInfo. How can I debug this?

nvim-sql

Issue with release 1.2

There seems to be an issue with release 1.2.

I've installed it like so

npm install -g sql-language-server

I'm getting this error when JupyterLab communicates with the sql-language-server

 [ERROR] default - uncaughtException TypeError: server_1.TextDocuments is not a constructor
    at createServerWithConnection (/opt/conda/lib/node_modules/sql-language-server/dist/src/createServer.js:48:21)
    at createServer (/opt/conda/lib/node_modules/sql-language-server/dist/src/createServer.js:311:12)
    at Object.handler (/opt/conda/lib/node_modules/sql-language-server/dist/bin/cli.js:25:37)
    at Object.runCommand (/opt/conda/lib/node_modules/sql-language-server/node_modules/yargs/lib/command.js:238:44)
    at Object.parseArgs [as _parseArgs] (/opt/conda/lib/node_modules/sql-language-server/node_modules/yargs/yargs.js:1063:30)
    at Object.get [as argv] (/opt/conda/lib/node_modules/sql-language-server/node_modules/yargs/yargs.js:1004:21)
    at Object.<anonymous> (/opt/conda/lib/node_modules/sql-language-server/dist/bin/cli.js:30:5)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)

I checked the version of vscode-languageserver using

npm list -g --depth 2 

it is at version [email protected]

this version is different than the one specified in the source code which is [email protected]

And when I look at the [email protected] version the file /opt/conda/lib/node_modules/sql-language-server/node_modules/vscode-languageserver/lib/common/server.js

does not contain a TextDocuments class

there seems to be a version issue with the npm package. I'm not sure how to resolve this issue.

Support Node10

When being used with sqlite3. Some diagnostics do work (Expected "--", "/*", "FROM", "GROUP", "LIMIT", "ORDER", "UNION", "WHERE", [ \t\n\r], or end of input but "X" found.) but most frequently it just throws this error.

TypeError: diagnostics.concat(...).flat is not a function
    at rules.forEach (/home/krassowski/jupyterlab-lsp/node_modules/sqlint/dist/src/rules/index.js:68:60)
    at Array.forEach (<anonymous>)
    at apply (/home/krassowski/jupyterlab-lsp/node_modules/sqlint/dist/src/rules/index.js:46:11)
    at walk (/home/krassowski/jupyterlab-lsp/node_modules/sqlint/dist/src/rules/index.js:77:38)
    at Object.values.forEach (/home/krassowski/jupyterlab-lsp/node_modules/sqlint/dist/src/rules/index.js:79:23)
    at Array.forEach (<anonymous>)
    at walk (/home/krassowski/jupyterlab-lsp/node_modules/sqlint/dist/src/rules/index.js:78:25)
    at Object.execute (/home/krassowski/jupyterlab-lsp/node_modules/sqlint/dist/src/rules/index.js:32:12)
    at Object.lint (/home/krassowski/jupyterlab-lsp/node_modules/sqlint/dist/src/cli/lint.js:52:53)
    at doLint (/home/krassowski/jupyterlab-lsp/node_modules/sql-language-server/dist/src/createDiagnostics.js:16:40)

This happens at:

diagnostics = diagnostics.concat(_diagnostics).flat();

The example _diagnostics content is:

[ { location: { start: [Object], end: [Object] },
    message: 'A linebreak is required after SELECT keyword',
    errorLevel: 2,
    fix: [ [Object], [Object] ],
    rulename: 'linebreak-after-clause-keyword' } ]

The diagnostics is just an empty array: [].

[].concat([{ message: 'A linebreak is required after SELECT keyword'}])

results in:

[{ message: 'A linebreak is required after SELECT keyword'}]

which does not have the flat() method in the node 10.

So the only problem is that the required runtime it Node 11+, but it is not specified in readme I guess... Or maybe the concat().flat() could be replaced with push() and spread operator?

Multiple SQL Statements Per File

When working on a local SQL file with this context:

SELECT * from table_1 where id = 1;
SELECT * from table_2 where id = 2;

I get the following error:

Error:Expected "--", "/*", [ \t\n\r], or end of input but "S" found.

This is using the NVIM 0.5 nightly build with vim-lsp.

Is this expected? And if so, is there a way to allow for multiple SQL statements in a single file like this?

False syntax error reported if DROP or ALTER command is used.

The fallowing SQL generates false error from your language serve:

/* Replace with your SQL commands */
DROP TABLE kittens;

false error1

The additional editor highlighting is supplied by "Error Lens" which makes the messages more visable but performs no checks of its own.

A similar message is displayed for:

/* Replace with your SQL commands */
ALTER TABLE kittens DROP COLUMN age;

And even:

/* Replace with your SQL commands */

That a comment fallowed by a blank line which is not an error in SQL.

sql-language-server did not work for mysql databases

The module mysql2/promise breaks my sql-language-server in my server.

I'm using vim with coc.nvim, and found exception as follows:

Error: Callback function is not available with promise clients.
    at PromiseConnection.query (.../sql-language-server/node_modules/mysql2/promise.js:94
    at .../sql-language-server/dist/src/database_libs/MysqlClient.js:62:29
    at new Promise (<anonymous>)
    at MysqlClient.getTables (.../sql-language-server/dist/src/database_libs/MysqlClient.
    at MysqlClient.getSchema (.../sql-language-server/dist/src/database_libs/AbstractClie
    at processTicksAndRejections (node:internal/process/task_queues:93:5)
    at async SettingStore.<anonymous> (.../sql-language-server/dist/src/createServer.js:8

After fixing (compilation output JS) codes the sql-langauge-server works correctly for me. I did not test following typescript patches, it's just a demostration.

diff --git a/packages/server/src/database_libs/MysqlClient.ts b/packages/server/src/database_libs/MysqlClient.ts
index 6f04e72..7a990f6 100644
--- a/packages/server/src/database_libs/MysqlClient.ts
+++ b/packages/server/src/database_libs/MysqlClient.ts
@@ -1,4 +1,4 @@
-import * as mysql from 'mysql2/promise'
+import * as mysql from 'mysql2'
 import * as mysqlType from 'mysql'
 import { Connection } from '../SettingStore'
 import AbstractClient, { RawField } from './AbstractClient'

Question about associating configuration with mime type

I'm using sql-language-server within JupyterLab that is using ipython magics %%sparksql and %%trino

https://github.com/CybercentreCanada/jupyterlab-sql-editor

In that environment each magic is associated with mime type of text/x-sparksql and text/x-trino. There is also an association with file extensions .sparksql and .trino.

I have registered a sql-language-server for each of these mime types. This enables me to switch configurations automatically. When a cell or a file that is of mime type text/x-sparksql it uses the spark configuration. If you edit a cell or file with the trino mime type it uses the other sql-language-server.

I'm now trying to achieve the same behavior in VSCode. That is I would like to switch configurations based on mime type. Either by editing a file with the proper extension or a notebook cell with the proper mime type.

I'm wondering what would entail to switch based on mime type.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.