├── .gitignore ├── images ├── add.png ├── Index.png ├── Queue.png ├── Route.png ├── Table.png ├── User.png ├── View.png ├── Assembly.png ├── Column.png ├── Contract.png ├── Database.png ├── Folder.png ├── Schema.png ├── Sequence.png ├── Service.png ├── Synonym.png ├── Trigger.png ├── Constraint.png ├── HDFSFolder.png ├── MasterKey.png ├── Server_red.png ├── SqlLogFile.png ├── Statistic.png ├── AsymmetricKey.png ├── Certificate.png ├── DatabaseRole.png ├── DefaultIcon.png ├── FileGroupFile.png ├── Key_UniqueKey.png ├── MessageType.png ├── Server_green.png ├── SymmetricKey.png ├── SystemQueue.png ├── SystemService.png ├── User_Disabled.png ├── add_inverse.png ├── ApplicationRole.png ├── BrokerPriority.png ├── ColumnMasterKey.png ├── DatabaseTrigger.png ├── FullTextCatalog.png ├── Key_ForeignKey.png ├── Key_PrimaryKey.png ├── PartitionScheme.png ├── SecurityPolicy.png ├── StoredProcedure.png ├── SystemContract.png ├── Table_Temporal.png ├── UserDefinedType.png ├── AggregateFunction.png ├── ExternalDataSource.png ├── ExternalFileFormat.png ├── FullTextStopList.png ├── PartitionFunction.png ├── SearchPropertyList.png ├── ServerLevelLogin.png ├── SystemBinaryString.png ├── SystemClrDataType.png ├── SystemDateAndTime.png ├── SystemExactNumeric.png ├── SystemMessageType.png ├── Trigger_Disabled.png ├── ColumnEncryptionKey.png ├── Database_Unavailable.png ├── RemoteServiceBinding.png ├── ScalarValuedFunction.png ├── ServerLevelEndpoint.png ├── SystemOtherDataType.png ├── TableValuedFunction.png ├── UserDefinedDataType.png ├── UserDefinedTableType.png ├── XmlSchemaCollection.png ├── DatabaseEncryptionKey.png ├── ServerLevelCredential.png ├── ServerLevelLinkedServer.png ├── ServerLevelServerAudit.png ├── ServerLevelServerRole.png ├── SystemCharacterString.png ├── SystemSpatialDataType.png ├── DatabaseScopedCredential.png ├── ServerLevelLogin_Disabled.png ├── ServerLevelServerTrigger.png ├── SystemApproximateNumeric.png ├── DatabaseAuditSpecification.png ├── ServerLevelLinkedServerLogin.png ├── SystemUnicodeCharacterString.png ├── UserDefinedTableTypeColumn.png ├── StoredProcedureParameter_Input.png ├── UserDefinedTableTypeConstraint.png ├── AggregateFunctionParameter_Input.png ├── AggregateFunctionParameter_Output.png ├── AggregateFunctionParameter_Return.png ├── DatabaseAndQueueEventNotification.png ├── ServerLevelCryptographicProvider.png ├── StoredProcedureParameter_Output.png ├── StoredProcedureParameter_Return.png ├── ScalarValuedFunctionParameter_Input.png ├── ServerLevelServerAuditSpecification.png ├── TableValuedFunctionParameter_Input.png ├── TableValuedFunctionParameter_Output.png ├── TableValuedFunctionParameter_Return.png ├── ScalarValuedFunctionParameter_Output.png ├── ScalarValuedFunctionParameter_Return.png └── ServerLevelLinkedServerLogin_Disabled.png ├── screenshots ├── demo.gif └── logo.png ├── .github ├── dependabot.yml └── workflows │ ├── docs.yml │ └── test.yml ├── snippets └── sql-mode │ ├── sqlListDatabases │ ├── sqlDeleteRows │ ├── sqlDropColumn │ ├── sqlSelect │ ├── sqlListTablesAndViews │ ├── sqlAddColumn │ ├── sqlUpdateRows │ ├── sqlDropStoredProc │ ├── sqlDropTable │ ├── sqlCreateDatabase │ ├── sqlInsertRows │ ├── sqlCreateTable │ ├── sqlListColumns │ ├── sqlDropDatabase │ ├── sqlExtensionHelp │ ├── sqlCreateStoredProc │ └── sqlGetSpaceUsed ├── docs └── stylesheets │ └── extra.css ├── Makefile ├── Eask ├── mkdocs.yml ├── LICENSE ├── README.org └── lsp-mssql.el /.gitignore: -------------------------------------------------------------------------------- 1 | .eask 2 | /dist 3 | *.elc 4 | -------------------------------------------------------------------------------- /images/add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/add.png -------------------------------------------------------------------------------- /images/Index.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Index.png -------------------------------------------------------------------------------- /images/Queue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Queue.png -------------------------------------------------------------------------------- /images/Route.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Route.png -------------------------------------------------------------------------------- /images/Table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Table.png -------------------------------------------------------------------------------- /images/User.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/User.png -------------------------------------------------------------------------------- /images/View.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/View.png -------------------------------------------------------------------------------- /images/Assembly.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Assembly.png -------------------------------------------------------------------------------- /images/Column.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Column.png -------------------------------------------------------------------------------- /images/Contract.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Contract.png -------------------------------------------------------------------------------- /images/Database.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Database.png -------------------------------------------------------------------------------- /images/Folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Folder.png -------------------------------------------------------------------------------- /images/Schema.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Schema.png -------------------------------------------------------------------------------- /images/Sequence.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Sequence.png -------------------------------------------------------------------------------- /images/Service.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Service.png -------------------------------------------------------------------------------- /images/Synonym.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Synonym.png -------------------------------------------------------------------------------- /images/Trigger.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Trigger.png -------------------------------------------------------------------------------- /images/Constraint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Constraint.png -------------------------------------------------------------------------------- /images/HDFSFolder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/HDFSFolder.png -------------------------------------------------------------------------------- /images/MasterKey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/MasterKey.png -------------------------------------------------------------------------------- /images/Server_red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Server_red.png -------------------------------------------------------------------------------- /images/SqlLogFile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/SqlLogFile.png -------------------------------------------------------------------------------- /images/Statistic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Statistic.png -------------------------------------------------------------------------------- /screenshots/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/screenshots/demo.gif -------------------------------------------------------------------------------- /screenshots/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/screenshots/logo.png -------------------------------------------------------------------------------- /images/AsymmetricKey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/AsymmetricKey.png -------------------------------------------------------------------------------- /images/Certificate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Certificate.png -------------------------------------------------------------------------------- /images/DatabaseRole.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/DatabaseRole.png -------------------------------------------------------------------------------- /images/DefaultIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/DefaultIcon.png -------------------------------------------------------------------------------- /images/FileGroupFile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/FileGroupFile.png -------------------------------------------------------------------------------- /images/Key_UniqueKey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Key_UniqueKey.png -------------------------------------------------------------------------------- /images/MessageType.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/MessageType.png -------------------------------------------------------------------------------- /images/Server_green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Server_green.png -------------------------------------------------------------------------------- /images/SymmetricKey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/SymmetricKey.png -------------------------------------------------------------------------------- /images/SystemQueue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/SystemQueue.png -------------------------------------------------------------------------------- /images/SystemService.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/SystemService.png -------------------------------------------------------------------------------- /images/User_Disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/User_Disabled.png -------------------------------------------------------------------------------- /images/add_inverse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/add_inverse.png -------------------------------------------------------------------------------- /images/ApplicationRole.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/ApplicationRole.png -------------------------------------------------------------------------------- /images/BrokerPriority.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/BrokerPriority.png -------------------------------------------------------------------------------- /images/ColumnMasterKey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/ColumnMasterKey.png -------------------------------------------------------------------------------- /images/DatabaseTrigger.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/DatabaseTrigger.png -------------------------------------------------------------------------------- /images/FullTextCatalog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/FullTextCatalog.png -------------------------------------------------------------------------------- /images/Key_ForeignKey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Key_ForeignKey.png -------------------------------------------------------------------------------- /images/Key_PrimaryKey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Key_PrimaryKey.png -------------------------------------------------------------------------------- /images/PartitionScheme.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/PartitionScheme.png -------------------------------------------------------------------------------- /images/SecurityPolicy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/SecurityPolicy.png -------------------------------------------------------------------------------- /images/StoredProcedure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/StoredProcedure.png -------------------------------------------------------------------------------- /images/SystemContract.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/SystemContract.png -------------------------------------------------------------------------------- /images/Table_Temporal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Table_Temporal.png -------------------------------------------------------------------------------- /images/UserDefinedType.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/UserDefinedType.png -------------------------------------------------------------------------------- /images/AggregateFunction.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/AggregateFunction.png -------------------------------------------------------------------------------- /images/ExternalDataSource.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/ExternalDataSource.png -------------------------------------------------------------------------------- /images/ExternalFileFormat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/ExternalFileFormat.png -------------------------------------------------------------------------------- /images/FullTextStopList.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/FullTextStopList.png -------------------------------------------------------------------------------- /images/PartitionFunction.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/PartitionFunction.png -------------------------------------------------------------------------------- /images/SearchPropertyList.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/SearchPropertyList.png -------------------------------------------------------------------------------- /images/ServerLevelLogin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/ServerLevelLogin.png -------------------------------------------------------------------------------- /images/SystemBinaryString.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/SystemBinaryString.png -------------------------------------------------------------------------------- /images/SystemClrDataType.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/SystemClrDataType.png -------------------------------------------------------------------------------- /images/SystemDateAndTime.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/SystemDateAndTime.png -------------------------------------------------------------------------------- /images/SystemExactNumeric.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/SystemExactNumeric.png -------------------------------------------------------------------------------- /images/SystemMessageType.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/SystemMessageType.png -------------------------------------------------------------------------------- /images/Trigger_Disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Trigger_Disabled.png -------------------------------------------------------------------------------- /images/ColumnEncryptionKey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/ColumnEncryptionKey.png -------------------------------------------------------------------------------- /images/Database_Unavailable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/Database_Unavailable.png -------------------------------------------------------------------------------- /images/RemoteServiceBinding.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/RemoteServiceBinding.png -------------------------------------------------------------------------------- /images/ScalarValuedFunction.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/ScalarValuedFunction.png -------------------------------------------------------------------------------- /images/ServerLevelEndpoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/ServerLevelEndpoint.png -------------------------------------------------------------------------------- /images/SystemOtherDataType.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/SystemOtherDataType.png -------------------------------------------------------------------------------- /images/TableValuedFunction.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/TableValuedFunction.png -------------------------------------------------------------------------------- /images/UserDefinedDataType.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/UserDefinedDataType.png -------------------------------------------------------------------------------- /images/UserDefinedTableType.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/UserDefinedTableType.png -------------------------------------------------------------------------------- /images/XmlSchemaCollection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/XmlSchemaCollection.png -------------------------------------------------------------------------------- /images/DatabaseEncryptionKey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/DatabaseEncryptionKey.png -------------------------------------------------------------------------------- /images/ServerLevelCredential.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/ServerLevelCredential.png -------------------------------------------------------------------------------- /images/ServerLevelLinkedServer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/ServerLevelLinkedServer.png -------------------------------------------------------------------------------- /images/ServerLevelServerAudit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/ServerLevelServerAudit.png -------------------------------------------------------------------------------- /images/ServerLevelServerRole.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/ServerLevelServerRole.png -------------------------------------------------------------------------------- /images/SystemCharacterString.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/SystemCharacterString.png -------------------------------------------------------------------------------- /images/SystemSpatialDataType.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/SystemSpatialDataType.png -------------------------------------------------------------------------------- /images/DatabaseScopedCredential.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/DatabaseScopedCredential.png -------------------------------------------------------------------------------- /images/ServerLevelLogin_Disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/ServerLevelLogin_Disabled.png -------------------------------------------------------------------------------- /images/ServerLevelServerTrigger.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/ServerLevelServerTrigger.png -------------------------------------------------------------------------------- /images/SystemApproximateNumeric.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/SystemApproximateNumeric.png -------------------------------------------------------------------------------- /images/DatabaseAuditSpecification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/DatabaseAuditSpecification.png -------------------------------------------------------------------------------- /images/ServerLevelLinkedServerLogin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/ServerLevelLinkedServerLogin.png -------------------------------------------------------------------------------- /images/SystemUnicodeCharacterString.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/SystemUnicodeCharacterString.png -------------------------------------------------------------------------------- /images/UserDefinedTableTypeColumn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/UserDefinedTableTypeColumn.png -------------------------------------------------------------------------------- /images/StoredProcedureParameter_Input.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/StoredProcedureParameter_Input.png -------------------------------------------------------------------------------- /images/UserDefinedTableTypeConstraint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/UserDefinedTableTypeConstraint.png -------------------------------------------------------------------------------- /images/AggregateFunctionParameter_Input.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/AggregateFunctionParameter_Input.png -------------------------------------------------------------------------------- /images/AggregateFunctionParameter_Output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/AggregateFunctionParameter_Output.png -------------------------------------------------------------------------------- /images/AggregateFunctionParameter_Return.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/AggregateFunctionParameter_Return.png -------------------------------------------------------------------------------- /images/DatabaseAndQueueEventNotification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/DatabaseAndQueueEventNotification.png -------------------------------------------------------------------------------- /images/ServerLevelCryptographicProvider.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/ServerLevelCryptographicProvider.png -------------------------------------------------------------------------------- /images/StoredProcedureParameter_Output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/StoredProcedureParameter_Output.png -------------------------------------------------------------------------------- /images/StoredProcedureParameter_Return.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/StoredProcedureParameter_Return.png -------------------------------------------------------------------------------- /images/ScalarValuedFunctionParameter_Input.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/ScalarValuedFunctionParameter_Input.png -------------------------------------------------------------------------------- /images/ServerLevelServerAuditSpecification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/ServerLevelServerAuditSpecification.png -------------------------------------------------------------------------------- /images/TableValuedFunctionParameter_Input.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/TableValuedFunctionParameter_Input.png -------------------------------------------------------------------------------- /images/TableValuedFunctionParameter_Output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/TableValuedFunctionParameter_Output.png -------------------------------------------------------------------------------- /images/TableValuedFunctionParameter_Return.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/TableValuedFunctionParameter_Return.png -------------------------------------------------------------------------------- /images/ScalarValuedFunctionParameter_Output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/ScalarValuedFunctionParameter_Output.png -------------------------------------------------------------------------------- /images/ScalarValuedFunctionParameter_Return.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/ScalarValuedFunctionParameter_Return.png -------------------------------------------------------------------------------- /images/ServerLevelLinkedServerLogin_Disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/emacs-lsp/lsp-mssql/HEAD/images/ServerLevelLinkedServerLogin_Disabled.png -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: github-actions 4 | directory: / 5 | schedule: 6 | interval: daily 7 | -------------------------------------------------------------------------------- /snippets/sql-mode/sqlListDatabases: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: List databases 3 | # key: sqlListDatabases 4 | # -- 5 | -- Get a list of databases 6 | SELECT name FROM sys.databases 7 | GO 8 | -------------------------------------------------------------------------------- /snippets/sql-mode/sqlDeleteRows: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: Delete rows from a Table 3 | # key: sqlDeleteRows 4 | # -- 5 | -- Delete rows from table '${1:TableName}' 6 | DELETE FROM $1 7 | WHERE $2 /* add search conditions here */ 8 | GO 9 | -------------------------------------------------------------------------------- /snippets/sql-mode/sqlDropColumn: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: Drop a column from a Table 3 | # key: sqlDropColumn 4 | # -- 5 | -- Drop '${1:ColumnName}' from table '${2:TableName}' in schema '${3:SchemaName}' 6 | ALTER TABLE $3.$2 7 | DROP COLUMN $1 8 | GO 9 | -------------------------------------------------------------------------------- /snippets/sql-mode/sqlSelect: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: Select rows from a Table or a View 3 | # key: sqlSelect 4 | # -- 5 | -- Select rows from a Table or View '${1:TableOrViewName}' in schema '${2:SchemaName}' 6 | SELECT * FROM $2.$1 7 | WHERE $3 /* add search conditions here */ 8 | GO 9 | -------------------------------------------------------------------------------- /snippets/sql-mode/sqlListTablesAndViews: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: List tables 3 | # key: sqlListTablesAndViews 4 | # -- 5 | -- Get a list of tables and views in the current database 6 | SELECT table_catalog [database], table_schema [schema], table_name name, table_type type 7 | FROM INFORMATION_SCHEMA.TABLES 8 | GO 9 | -------------------------------------------------------------------------------- /docs/stylesheets/extra.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --md-primary-fg-color: #333333; 3 | --md-accent-fg-color: #EB7A2F; 4 | --md-default-fg-color--light: #999999; 5 | } 6 | 7 | .md-footer { 8 | --md-default-fg-color: #333333; 9 | } 10 | 11 | .md-grid { 12 | max-width: 70rem; 13 | } 14 | 15 | .md-typeset a { 16 | color: #999999; 17 | } 18 | -------------------------------------------------------------------------------- /snippets/sql-mode/sqlAddColumn: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: Add a new column to a Table 3 | # key: sqlAddColumn 4 | # -- 5 | -- Add a new column '${1:NewColumnName}' to table '${2:TableName}' in schema '${3:SchemaName}' 6 | ALTER TABLE $3.$2 7 | ADD $1 /*new_column_name*/ int /*new_column_datatype*/ NULL /*new_column_nullability*/ 8 | GO 9 | -------------------------------------------------------------------------------- /snippets/sql-mode/sqlUpdateRows: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: Update rows in a Table 3 | # key: sqlUpdateRows 4 | # -- 5 | -- Update rows in table '${1:TableName}' 6 | UPDATE $1 7 | SET 8 | $2[Colum1] = Colum1_Value, 9 | $3[Colum2] = Colum2_Value 10 | -- add more columns and values here 11 | WHERE $4 /* add search conditions here */ 12 | GO 13 | -------------------------------------------------------------------------------- /snippets/sql-mode/sqlDropStoredProc: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: Drop a stored procedure 3 | # key: sqlDropStoredProc 4 | # -- 5 | -- Drop the stored procedure called '${1:StoredProcedureName}' in schema '${2:SchemaName}' 6 | IF EXISTS ( 7 | SELECT * 8 | FROM INFORMATION_SCHEMA.ROUTINES 9 | WHERE SPECIFIC_SCHEMA = N'$2' 10 | AND SPECIFIC_NAME = N'$1' 11 | ) 12 | DROP PROCEDURE $2.$1 13 | GO 14 | -------------------------------------------------------------------------------- /snippets/sql-mode/sqlDropTable: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: Drop a Table 3 | # key: sqlDropTable 4 | # -- 5 | -- Drop the table '${1:TableName}' in schema '${2:SchemaName}' 6 | IF EXISTS ( 7 | SELECT * 8 | FROM sys.tables 9 | JOIN sys.schemas 10 | ON sys.tables.schema_id = sys.schemas.schema_id 11 | WHERE sys.schemas.name = N'$2' 12 | AND sys.tables.name = N'$1' 13 | ) 14 | DROP TABLE $2.$1 15 | GO 16 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SHELL=/usr/bin/env bash 2 | 3 | EMACS ?= emacs 4 | EASK ?= eask 5 | 6 | ci: build compile checkdoc 7 | 8 | build: 9 | $(EASK) package 10 | $(EASK) install 11 | 12 | compile: 13 | @echo "Compiling..." 14 | $(EASK) compile 15 | 16 | checkdoc: 17 | $(EASK) lint checkdoc 18 | 19 | lint: 20 | @echo "package linting..." 21 | $(EASK) lint package 22 | 23 | clean: 24 | $(EASK) clean all 25 | 26 | .PHONY: test compile checkdoc lint clean 27 | -------------------------------------------------------------------------------- /snippets/sql-mode/sqlCreateDatabase: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: Create a new Database 3 | # key: sqlCreateDatabase 4 | # -- 5 | -- Create a new database called '${1:DatabaseName}' 6 | -- Connect to the 'master' database to run this snippet 7 | USE master 8 | GO 9 | -- Create the new database if it does not exist already 10 | IF NOT EXISTS ( 11 | SELECT name 12 | FROM sys.databases 13 | WHERE name = N'$1' 14 | ) 15 | CREATE DATABASE $1 16 | GO 17 | -------------------------------------------------------------------------------- /snippets/sql-mode/sqlInsertRows: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: Insert rows into a Table 3 | # key: sqlInsertRows 4 | # -- 5 | -- Insert rows into table '${1:TableName}' 6 | INSERT INTO $1 7 | ( -- columns to insert data into 8 | $2[Column1], [Column2], [Column3] 9 | ) 10 | VALUES 11 | ( -- first row: values for the columns in the list above 12 | $3Column1_Value, Column2_Value, Column3_Value 13 | ), 14 | ( -- second row: values for the columns in the list above 15 | $4Column1_Value, Column2_Value, Column3_Value 16 | ) 17 | -- add more rows here 18 | GO 19 | -------------------------------------------------------------------------------- /snippets/sql-mode/sqlCreateTable: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: Create a new Table 3 | # key: sqlCreateTable 4 | # -- 5 | -- Create a new table called '${1:TableName}' in schema '${2:SchemaName}' 6 | -- Drop the table if it already exists 7 | IF OBJECT_ID('$2.$1', 'U') IS NOT NULL 8 | DROP TABLE $2.$1 9 | GO 10 | -- Create the table in the specified schema 11 | CREATE TABLE $2.$1 12 | ( 13 | $1Id INT NOT NULL PRIMARY KEY, -- primary key column 14 | $3Column1 [NVARCHAR](50) NOT NULL, 15 | $4Column2 [NVARCHAR](50) NOT NULL 16 | -- specify more columns here 17 | ); 18 | GO 19 | -------------------------------------------------------------------------------- /snippets/sql-mode/sqlListColumns: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: List columns 3 | # key: sqlListColumns 4 | # -- 5 | -- List columns in all tables whose name is like '${1:TableName}' 6 | SELECT 7 | TableName = tbl.TABLE_SCHEMA + '.' + tbl.TABLE_NAME, 8 | ColumnName = col.COLUMN_NAME, 9 | ColumnDataType = col.DATA_TYPE 10 | FROM INFORMATION_SCHEMA.TABLES tbl 11 | INNER JOIN INFORMATION_SCHEMA.COLUMNS col 12 | ON col.TABLE_NAME = tbl.TABLE_NAME 13 | AND col.TABLE_SCHEMA = tbl.TABLE_SCHEMA 14 | 15 | WHERE tbl.TABLE_TYPE = 'BASE TABLE' and tbl.TABLE_NAME like '%$1%' 16 | GO 17 | -------------------------------------------------------------------------------- /snippets/sql-mode/sqlDropDatabase: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: Drop a Database 3 | # key: sqlDropDatabase 4 | # -- 5 | -- Drop the database '${1:DatabaseName}' 6 | -- Connect to the 'master' database to run this snippet 7 | USE master 8 | GO 9 | -- Uncomment the ALTER DATABASE statement below to set the database to SINGLE_USER mode if the drop database command fails because the database is in use. 10 | -- ALTER DATABASE $1 SET SINGLE_USER WITH ROLLBACK IMMEDIATE; 11 | -- Drop the database if it exists 12 | IF EXISTS ( 13 | SELECT name 14 | FROM sys.databases 15 | WHERE name = N'$1' 16 | ) 17 | DROP DATABASE $1 18 | GO 19 | -------------------------------------------------------------------------------- /Eask: -------------------------------------------------------------------------------- 1 | ;; -*- mode: eask; lexical-binding: t -*- 2 | 3 | (package "lsp-mssql" 4 | "0.1" 5 | "MSSQL LSP bindings") 6 | 7 | (website-url "https://github.com/emacs-lsp/lsp-mssql") 8 | (keywords "data" "languages") 9 | 10 | (package-file "lsp-mssql.el") 11 | 12 | (script "test" "echo \"Error: no test specified\" && exit 1") 13 | 14 | (source 'gnu) 15 | (source 'melpa) 16 | 17 | (depends-on "emacs" "28.1") 18 | (depends-on "lsp-mode") 19 | (depends-on "dash") 20 | (depends-on "f") 21 | (depends-on "ht") 22 | (depends-on "lsp-treemacs") 23 | 24 | (setq network-security-level 'low) ; see https://github.com/jcs090218/setup-emacs-windows/issues/156#issuecomment-932956432 25 | -------------------------------------------------------------------------------- /.github/workflows/docs.yml: -------------------------------------------------------------------------------- 1 | name: Docs 2 | 3 | on: 4 | push: 5 | 6 | jobs: 7 | build: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Checkout 11 | uses: actions/checkout@v6 12 | 13 | - name: README.org -> README.md 14 | uses: docker://pandoc/core:2.9 15 | with: 16 | args: -s README.org -t gfm -o docs/README.md 17 | 18 | - name: MkDocs 19 | run: | 20 | cp -rf screenshots docs 21 | docker login docker.pkg.github.com --username $GITHUB_ACTOR --password ${{ secrets.GITHUB_TOKEN }} 22 | docker run --rm -v ${PWD}:/docs docker.pkg.github.com/emacs-lsp/docs-image/docs-image -- build 23 | 24 | - name: Deploy 25 | uses: peaceiris/actions-gh-pages@v4 26 | with: 27 | github_token: ${{ secrets.GITHUB_TOKEN }} 28 | publish_dir: ./site 29 | -------------------------------------------------------------------------------- /snippets/sql-mode/sqlExtensionHelp: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: Get extension help 3 | # key: sqlExtensionHelp 4 | # -- 5 | /* 6 | mssql getting started: 7 | ----------------------------- 8 | 1. Change language mode to SQL: Open a .sql file or press Ctrl+K M (Cmd+K M on Mac) and choose 'SQL'. 9 | 2. Connect to a database: Press F1 to show the command palette, type 'sqlcon' or 'sql' then click 'Connect'. 10 | 3. Use the T-SQL editor: Type T-SQL statements in the editor using T-SQL IntelliSense or type 'sql' to see a list of code snippets you can tweak & reuse. 11 | 4. Run T-SQL statements: Press F1 and type 'sqlex' or press Ctrl+Shift+e (Cmd+Shift+e on Mac) to execute all the T-SQL code in the editor. 12 | 13 | Tip #1: Put GO on a line by itself to separate T-SQL batches. 14 | Tip #2: Select some T-SQL text in the editor and press `Ctrl+Shift+e` (`Cmd+Shift+e` on Mac) to execute the selection 15 | */ 16 | -------------------------------------------------------------------------------- /snippets/sql-mode/sqlCreateStoredProc: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: Create a stored procedure 3 | # key: sqlCreateStoredProc 4 | # -- 5 | -- Create a new stored procedure called '${1:StoredProcedureName}' in schema '${2:SchemaName}' 6 | -- Drop the stored procedure if it already exists 7 | IF EXISTS ( 8 | SELECT * 9 | FROM INFORMATION_SCHEMA.ROUTINES 10 | WHERE SPECIFIC_SCHEMA = N'$2' 11 | AND SPECIFIC_NAME = N'$1' 12 | ) 13 | DROP PROCEDURE $2.$1 14 | GO 15 | -- Create the stored procedure in the specified schema 16 | CREATE PROCEDURE $2.$1 17 | $3@param1 /*parameter name*/ int /*datatype_for_param1*/ = 0, /*default_value_for_param1*/ 18 | $4@param2 /*parameter name*/ int /*datatype_for_param1*/ = 0 /*default_value_for_param2*/ 19 | -- add more stored procedure parameters here 20 | AS 21 | -- body of the stored procedure 22 | SELECT @param1, @param2 23 | GO 24 | -- example to execute the stored procedure we just created 25 | EXECUTE $2.$1 1 /*value_for_param1*/, 2 /*value_for_param2*/ 26 | GO 27 | -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: LSP MSSQL 2 | 3 | extra_css: 4 | - stylesheets/extra.css 5 | 6 | theme: 7 | name: material 8 | logo: screenshots/logo.png 9 | favicon: screenshots/logo.png 10 | icon: 11 | repo: fontawesome/brands/github 12 | 13 | extra: 14 | social: 15 | - icon: fontawesome/brands/github-alt 16 | link: https://github.com/emacs-lsp/lsp-mssql 17 | - icon: fontawesome/brands/twitter 18 | link: https://twitter.com/yonchovski 19 | - icon: fontawesome/brands/gitter 20 | link: https://gitter.im/emacs-lsp/lsp-mode 21 | 22 | repo_name: emacs-lsp/lsp-mssql 23 | repo_url: https://github.com/emacs-lsp/lsp-mssql 24 | 25 | markdown_extensions: 26 | - pymdownx.superfences 27 | - pymdownx.emoji: 28 | emoji_index: !!python/name:materialx.emoji.twemoji 29 | emoji_generator: !!python/name:materialx.emoji.to_svg 30 | - codehilite 31 | - toc: 32 | permalink: '#' 33 | 34 | plugins: 35 | - search 36 | - awesome-pages 37 | - git-revision-date-localized 38 | -------------------------------------------------------------------------------- /snippets/sql-mode/sqlGetSpaceUsed: -------------------------------------------------------------------------------- 1 | # -*- mode: snippet -*- 2 | # name: Show space used by tables 3 | # key: sqlGetSpaceUsed 4 | # -- 5 | -- Get the space used by table ${1:TableName} 6 | SELECT TABL.name AS table_name, 7 | INDX.name AS index_name, 8 | SUM(PART.rows) AS rows_count, 9 | SUM(ALOC.total_pages) AS total_pages, 10 | SUM(ALOC.used_pages) AS used_pages, 11 | SUM(ALOC.data_pages) AS data_pages, 12 | (SUM(ALOC.total_pages)*8/1024) AS total_space_MB, 13 | (SUM(ALOC.used_pages)*8/1024) AS used_space_MB, 14 | (SUM(ALOC.data_pages)*8/1024) AS data_space_MB 15 | FROM sys.tables AS TABL 16 | INNER JOIN sys.indexes AS INDX 17 | ON TABL.object_id = INDX.object_id 18 | INNER JOIN sys.partitions AS PART 19 | ON INDX.object_id = PART.object_id 20 | AND INDX.index_id = PART.index_id 21 | INNER JOIN sys.allocation_units AS ALOC 22 | ON PART.partition_id = ALOC.container_id 23 | WHERE TABL.name LIKE '%$1%' 24 | AND INDX.object_id > 255 25 | AND INDX.index_id <= 1 26 | GROUP BY TABL.name, 27 | INDX.object_id, 28 | INDX.index_id, 29 | INDX.name 30 | ORDER BY Object_Name(INDX.object_id), 31 | (SUM(ALOC.total_pages)*8/1024) DESC 32 | GO 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Ivan Yonchovski 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - master 10 | workflow_dispatch: 11 | 12 | jobs: 13 | build: 14 | runs-on: ${{ matrix.os }} 15 | continue-on-error: ${{ matrix.experimental }} 16 | strategy: 17 | fail-fast: false 18 | matrix: 19 | os: [ubuntu-latest, macos-latest, windows-latest] 20 | emacs-version: 21 | - 28.2 22 | - 29.4 23 | - 30.2 24 | experimental: [false] 25 | include: 26 | - os: ubuntu-latest 27 | emacs-version: snapshot 28 | experimental: true 29 | - os: macos-latest 30 | emacs-version: snapshot 31 | experimental: true 32 | - os: windows-latest 33 | emacs-version: snapshot 34 | experimental: true 35 | 36 | steps: 37 | - uses: actions/checkout@v6 38 | 39 | - uses: jcs090218/setup-emacs@master 40 | with: 41 | version: ${{ matrix.emacs-version }} 42 | 43 | - uses: emacs-eask/setup-eask@master 44 | with: 45 | version: 'snapshot' 46 | 47 | - name: Run tests 48 | run: 'make ci' 49 | -------------------------------------------------------------------------------- /README.org: -------------------------------------------------------------------------------- 1 | [[https://melpa.org/#/lsp-mssql][file:https://melpa.org/packages/lsp-mssql-badge.svg]] 2 | [[https://github.com/emacs-lsp/lsp-mssql/actions/workflows/test.yml][file:https://github.com/emacs-lsp/lsp-mssql/actions/workflows/test.yml/badge.svg]] 3 | 4 | * lsp-mode mssql client 5 | Emacs client for [[https://github.com/microsoft/sqltoolsservice][sqltoolsservice]] (port of [[https://github.com/microsoft/vscode-mssql/][vscode-mssql]]) 6 | ** Demo 7 | [[file:screenshots/demo.gif]] 8 | ** Installation 9 | *** Melpa (TBD) 10 | *** Manual 11 | Install =lsp-mode= and =lsp-treemacs= clone the repo and add the following lines in your config: 12 | #+BEGIN_SRC elisp 13 | (add-to-load-path ".../lsp-mssql/") 14 | (require 'lsp-mssql) 15 | (add-hook 'sql-mode-hook 'lsp) 16 | #+END_SRC 17 | ** Configuration 18 | Confgure the connections. 19 | #+BEGIN_SRC emacs-lisp 20 | (setq lsp-mssql-connections 21 | [(:server "localhost" 22 | :database "" 23 | :user "SA" 24 | :password "demoPWD2")]) 25 | #+END_SRC 26 | Open a =*.sql= file and do =M-x lsp=. On the first run, it will ask you 27 | whether to install the language server. Then when you are in the =sql= buffer 28 | do =M-x lsp-mssql-connect= which will ask you to select connection. After the 29 | connection is established the current buffer will be associated with the SQL 30 | Server and the completion and the query exection will be performed against 31 | that server. 32 | 33 | =lsp-mssql= also supports Azure MSSQL. To connect using Service 34 | Principals, you need to use raw connection string: 35 | 36 | #+begin_src emacs-lisp 37 | (setq lsp-mssql-connections 38 | [(:server "SERVER-NAME.database.windows.net" 39 | :connectionString "SERVER=SERVER-NAME.database.windows.net;DATABASE=...;UID=...;PWD=...;AUTHENTICATION=ActiveDirectoryServicePrincipal")]) 40 | #+end_src 41 | 42 | ** Commands 43 | - Editor 44 | - =lsp-mssql-connect= - connect the editor to =MSSQL server=. 45 | - =lsp-mssql-disconnect= - disconnect the editor =MSSQL server=. 46 | - =lsp-mssql-execute-buffer= - execute current buffer 47 | - =lsp-mssql-execute-region= - execute selected region. 48 | - MSSQL Object Explorer 49 | - =lsp-mssql-object-explorer= - display =MSSQL= object explorer to the right. 50 | - =lsp-mssql-object-explorer-connect= - connect the connection under point. Bound to =C= in the object explorer. 51 | - =lsp-mssql-object-explorer-refresh= - refresh the node. Bound to =R= in the object explorer. 52 | ** Run mssql in docker 53 | #+BEGIN_SRC bash 54 | docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=demoPWD2" \ 55 | -p 1433:1433 --name sql1 \ 56 | -d mcr.microsoft.com/mssql/server:2019-GA-ubuntu-16.04 57 | #+END_SRC 58 | ** Snippets 59 | =snippets= directory contains the snippets from [[https://github.com/microsoft/vscode-mssql/][vscode-mssql]]. 60 | #+BEGIN_SRC emacs-lisp 61 | (add-to-list 'yas-snippets-dir "path to stippets dir.") 62 | #+END_SRC 63 | ** TBD 64 | - Implement disconnect. 65 | - Implement cancel query 66 | - Provide options to customize the output 67 | -------------------------------------------------------------------------------- /lsp-mssql.el: -------------------------------------------------------------------------------- 1 | ;;; lsp-mssql.el --- MSSQL LSP bindings -*- lexical-binding: t; -*- 2 | 3 | ;; Copyright (C) 2019 Ivan Yonchovski 4 | ;; Copyright (C) 2019-2025 emacs-lsp maintainers 5 | ;; Version: 0.1 6 | 7 | ;; Author: Ivan Yonchovski 8 | ;; Keywords: data, languages 9 | ;; Package-Requires: ((emacs "28.1") (lsp-mode "6.2") (dash "2.14.1") (f "0.20.0") (ht "2.0") (lsp-treemacs "0.1")) 10 | ;; URL: https://github.com/emacs-lsp/lsp-mssql 11 | 12 | ;; This program is free software; you can redistribute it and/or modify 13 | ;; it under the terms of the GNU General Public License as published by 14 | ;; the Free Software Foundation, either version 3 of the License, or 15 | ;; (at your option) any later version. 16 | 17 | ;; This program is distributed in the hope that it will be useful, 18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | ;; GNU General Public License for more details. 21 | 22 | ;; You should have received a copy of the GNU General Public License 23 | ;; along with this program. If not, see . 24 | 25 | ;;; Commentary: 26 | ;; lsp-mode client for MSSQL language server. 27 | 28 | ;;; Code: 29 | 30 | (require 'lsp-mode) 31 | (require 'lsp-treemacs) 32 | (require 'gnutls) 33 | 34 | (defgroup lsp-mssql nil 35 | "LSP support for the MSSQL server." 36 | :link '(url-link "https://github.com/microsoft/sqltoolsservice") 37 | :group 'lsp-mode) 38 | 39 | (defcustom lsp-mssql-download-location 40 | (expand-file-name "mssql/" user-emacs-directory) 41 | "Server download location." 42 | :type 'directory) 43 | 44 | (defcustom lsp-mssql-default-batch-size 10 45 | "Default number of items to load per query." 46 | :type 'number) 47 | 48 | (defconst lsp-mssql-server-download-url 49 | "https://download.microsoft.com/download/c/2/f/c9857f58-e569-4677-ad24-f180e83a8252/microsoft.sqltools.servicelayer-%s") 50 | 51 | (defconst lsp-mssql-executable-files 52 | '("MicrosoftSqlToolsServiceLayer.exe" "MicrosoftSqlToolsServiceLayer" "MicrosoftSqlToolsServiceLayer.dll")) 53 | 54 | (declare-function org-mode "ext:org" ()) 55 | (declare-function org-show-all "ext:org" (types)) 56 | (declare-function org-table-align "ext:org-table" ()) 57 | 58 | (defvar lsp-mssql--connection-name->session-id (ht)) 59 | 60 | (defvar-local lsp-mssql-buffer-status nil 61 | "SQL buffer status.") 62 | 63 | (defvar-local lsp-mssql-result-metadata nil 64 | "Metadata associated with result set. 65 | 66 | This is stored in the result buffer as buffer local value.") 67 | 68 | (put 'lsp-mssql-buffer-status 'risky-local-variable t) 69 | (add-to-list 'global-mode-string (list '(t lsp-mssql-buffer-status))) 70 | 71 | (defun lsp-mssql--extract (filename target-dir) 72 | "Extracts FILENAME into TARGET-DIR." 73 | (cond 74 | ((eq system-type 'windows-nt) 75 | ;; on windows, we attempt to use powershell v5+, available on Windows 10+ 76 | (let ((powershell-version (substring 77 | (shell-command-to-string "powershell -command \"(Get-Host).Version.Major\"") 78 | 0 -1))) 79 | (if (>= (string-to-number powershell-version) 5) 80 | (call-process "powershell" 81 | nil 82 | nil 83 | nil 84 | "-command" 85 | (concat "add-type -assembly system.io.compression.filesystem;" 86 | "[io.compression.zipfile]::ExtractToDirectory(\"" filename "\", \"" target-dir "\")")) 87 | 88 | (message (concat "lsp-csharp: for automatic server installation procedure" 89 | " to work on Windows you need to have powershell v5+ installed"))))) 90 | 91 | ((or (eq system-type 'gnu/linux) 92 | (eq system-type 'darwin)) 93 | (call-process "tar" nil nil t "xf" filename "-C" target-dir)) 94 | 95 | (t (error "MSSQL server cannot extract \"%s\" on platform %s (yet)" filename system-type)))) 96 | 97 | (defun lsp-mssql--download (url filename) 98 | "Downloads file from URL as FILENAME. 99 | Will not do anything should the file exist already." 100 | (let ((gnutls-algorithm-priority 101 | (if (and (not gnutls-algorithm-priority) 102 | (boundp 'libgnutls-version) 103 | (>= libgnutls-version 30603) 104 | (version<= emacs-version "26.2")) 105 | "NORMAL:-VERS-TLS1.3" 106 | gnutls-algorithm-priority))) 107 | (url-copy-file url filename t))) 108 | 109 | 110 | (defun lsp-mssql-download-server () 111 | "Download mssql server. 112 | Uses `powershell' on windows and `tar' on Linux to extract the server binary." 113 | (interactive) 114 | (let* ((result (cond ((eq system-type 'darwin) "osx-x64-netcoreapp2.2.tar.gz") 115 | ((eq system-type 'gnu/linux) "rhel-x64-netcoreapp2.2.tar.gz") 116 | ((eq system-type 'windows-nt) "win-x64-netcoreapp2.2.zip") 117 | (t (error (format "Unsupported system: %s" system-type))))) 118 | (download-location (f-join temporary-file-directory result)) 119 | (url (format lsp-mssql-server-download-url result))) 120 | (lsp--info "Starting downloading mssql server in %s from %s." download-location url) 121 | (lsp-mssql--download url download-location) 122 | (mkdir lsp-mssql-download-location t) 123 | (lsp-mssql--extract download-location lsp-mssql-download-location) 124 | 125 | (seq-doseq (file lsp-mssql-executable-files) 126 | (let ((target-file (f-join lsp-mssql-download-location file))) 127 | (when (f-exists? target-file) 128 | (chmod target-file #o755))))) 129 | (lsp--info "Downloading mssql server finished.")) 130 | 131 | (defun lsp-mssql--expand-completed (workspace params) 132 | "Expand completed handler. 133 | WORKSPACE is the active workspace. 134 | PARAMS expand completed params." 135 | (-let [(&hash "nodePath" node-path "nodes") params] 136 | (puthash (cons node-path nil) 137 | (append nodes nil) 138 | (gethash "explorer" (lsp--workspace-metadata workspace)) ) 139 | (lsp-mssql-object-explorer))) 140 | 141 | (defun lsp-mssql--session-created (workspace params) 142 | "Session created handler. 143 | WORKSPACE is the active workspace. 144 | PARAMS Session created handler." 145 | (-let [(&hash "rootNode" root-node "sessionId" session-id) params] 146 | (puthash (cons session-id t) 147 | (list root-node) 148 | (gethash "explorer" (lsp--workspace-metadata workspace)) ) 149 | (lsp-mssql-object-explorer))) 150 | 151 | (defcustom lsp-mssql-log-debug-info nil 152 | "[Optional] Log debug output to the VS Code console (Help -> Toggle Developer Tools)." 153 | :type 'boolean) 154 | 155 | (define-widget 'lsp-connection-vector 'lazy 156 | "Connection vector." 157 | :offset 4 158 | :tag "Connections Vector" 159 | :type '(restricted-sexp 160 | :match-alternatives (lambda (candidate) 161 | (and 162 | (vectorp candidate) 163 | (seq-every-p #'listp candidate))))) 164 | 165 | (defcustom lsp-mssql-connections ['(:server "{{put-server-name-here}}" 166 | :database "{{put-database-name-here}}" 167 | :user "{{put-username-here}}" 168 | :password "{{put-password-here}}")] 169 | "Connection profiles defined in 'User Settings' are shown under 'MS SQL: Connect' command in the command palette." 170 | :type 'lsp-connection-vector) 171 | 172 | (defcustom lsp-mssql-intelli-sense-enable-intelli-sense t 173 | "Should IntelliSense be enabled." 174 | :type 'boolean) 175 | 176 | (defcustom lsp-mssql-intelli-sense-enable-error-checking t 177 | "Should IntelliSense error checking be enabled." 178 | :type 'boolean) 179 | 180 | (defcustom lsp-mssql-intelli-sense-enable-suggestions t 181 | "Should IntelliSense suggestions be enabled." 182 | :type 'boolean) 183 | 184 | (defcustom lsp-mssql-intelli-sense-enable-quick-info t 185 | "Should IntelliSense quick info be enabled." 186 | :type 'boolean) 187 | 188 | (defcustom lsp-mssql-intelli-sense-lower-case-suggestions t 189 | "Should IntelliSense suggestions be lowercase." 190 | :type 'boolean) 191 | 192 | (lsp-register-custom-settings 193 | '(("mssql.intelliSense.lowerCaseSuggestions" lsp-mssql-intelli-sense-lower-case-suggestions t) 194 | ("mssql.intelliSense.enableQuickInfo" lsp-mssql-intelli-sense-enable-quick-info t) 195 | ("mssql.intelliSense.enableSuggestions" lsp-mssql-intelli-sense-enable-suggestions t) 196 | ("mssql.intelliSense.enableErrorChecking" lsp-mssql-intelli-sense-enable-error-checking t) 197 | ("mssql.intelliSense.enableIntelliSense" lsp-mssql-intelli-sense-enable-intelli-sense t) 198 | ("mssql.connections" lsp-mssql-connections) 199 | ("mssql.logDebugInfo" lsp-mssql-log-debug-info t))) 200 | 201 | (defmacro lsp-mssql-with-result-buffer (&rest body) 202 | "Evaluate BODY in result buffer." 203 | (declare (debug (body))) 204 | `(with-current-buffer (get-buffer-create "*SQL Results*") 205 | (prog1 (save-excursion 206 | (let ((inhibit-read-only t)) 207 | ,@body)) 208 | (org-show-all '(headings blocks))))) 209 | 210 | (defun lsp-mssql--connection-complete (_workspace params) 211 | "Connection completed handler. 212 | PARAMS connection completed params." 213 | ;; (setq params my/params) 214 | (if (gethash "connectionId" params) 215 | 216 | (-let [(&hash "ownerUri" owner 217 | "connectionSummary" (&hash "serverName" server-name "databaseName" database-name)) params] 218 | (lsp--info "Successfully connected to %s, database: %s" server-name database-name) 219 | (when-let (buffer (find-buffer-visiting (lsp--uri-to-path owner))) 220 | (with-current-buffer buffer 221 | (setq lsp-mssql-buffer-status (propertize (format "database::%s:%s" server-name database-name) 222 | 'face 'success))))) 223 | (-let [(&hash "errorMessage" error-message 224 | "errorNumber" error-number) params] 225 | (lsp--error "Failed to connect with the following error error number: %s\n%s" error-number error-message)))) 226 | 227 | (defun lsp-mssql--result-set-available (_workspace _params) 228 | "Result set available handler.") 229 | 230 | (defun lsp-mssql--message (_workspace params) 231 | "Message handler. 232 | PARAMS the params." 233 | (-let [(&hash "message" (&hash "message" "time" "isError" is-error)) params] 234 | (funcall (if is-error 'lsp--error 'lsp--info) (format "%s %s" time message)))) 235 | 236 | (defun lsp-mssql--result-set-updated (_workspace _params) 237 | "Result set update handler.") 238 | 239 | (defun lsp-mssql--render-table (result) 240 | "Render RESULT as a table." 241 | (->> result 242 | (gethash "resultSubset") 243 | (gethash "rows") 244 | (seq-map (lambda (item) 245 | (->> item 246 | (seq-map (-lambda ((&hash "displayValue")) 247 | (concat "|" displayValue))) 248 | (apply #'concat)))) 249 | (s-join "|\n"))) 250 | 251 | (defun lsp-mssql--replace-overlay-text (ov string) 252 | "Replace text inside overlay OV with STRING." 253 | (let ((start (overlay-start ov))) 254 | (save-excursion 255 | ;; This is a bit silly, but this way we don't have to make new 256 | ;; buttons, we just replace the text inside an exisiting button. 257 | ;; We can't insert at the start of the overlay because that 258 | ;; would only push the existing one away, not inserting the new 259 | ;; text into it. 260 | (goto-char (1+ start)) 261 | (insert string) 262 | (delete-region (point) (overlay-end ov)) 263 | (goto-char (1+ start)) 264 | (delete-char -1)))) 265 | 266 | (defvar lsp-mssql-after-render-table-hook nil 267 | "Hook called after data is rendered in the result buffer. 268 | 269 | When the hook is called, the point is at the end of the buffer.") 270 | 271 | (defun lsp-mssql--result-set-complete (workspace params) 272 | "Result set complete handler. 273 | WORKSPACE is the active workspace. 274 | PARAMS the params." 275 | (-let* ((column-info (gethash "columnInfo" (gethash "resultSetSummary" params))) 276 | (result-metadata (seq-map (-lambda ((&hash "columnName" name "dataTypeName" type)) 277 | (list name :name name :type type)) 278 | column-info)) 279 | (marker (lsp-mssql-with-result-buffer 280 | (setq-local lsp-mssql-result-metadata result-metadata) 281 | (goto-char (point-max)) 282 | (insert (format "|%s|\n"(s-join "|" (seq-map (-lambda ((&hash "columnName" name)) 283 | name) 284 | column-info)))) 285 | (insert "|-") 286 | (org-table-align) 287 | (goto-char (point-at-eol)) 288 | (copy-marker (point)))) 289 | ((&hash "ownerUri" owner-uri 290 | "resultSetSummary"(&hash "rowCount" row-count "batchId" "id")) params) 291 | (loaded-index 0) 292 | (to-load lsp-mssql-default-batch-size) 293 | more-items-marker) 294 | (cl-labels ((subset-params 295 | () 296 | (if (< loaded-index row-count) 297 | (let ((to-load (if (> (+ loaded-index to-load) row-count) 298 | (- row-count loaded-index) 299 | to-load))) 300 | `(:ownerUri ,owner-uri 301 | :resultSetIndex ,id 302 | :rowsCount ,to-load 303 | :rowsStartIndex ,(prog1 loaded-index 304 | (setf loaded-index (+ loaded-index to-load))) 305 | :batchIndex ,batchId)) 306 | (lsp--info "All items are loaded") 307 | nil)) 308 | (render-load-more 309 | () 310 | (if (= loaded-index row-count) 311 | (progn 312 | (when (looking-at-p "^Load") 313 | (delete-region (line-beginning-position) (line-end-position))) 314 | (insert "|-") 315 | (org-table-align) 316 | (end-of-line)) 317 | (if (looking-at-p "^Load") 318 | (lsp-mssql--replace-overlay-text 319 | (car (overlays-at (point))) 320 | (format "Load %s more... (%s/%s)" to-load loaded-index row-count)) 321 | (insert (format "Load %s more... (%s/%s)" to-load loaded-index row-count)))))) 322 | (when-let ((params (subset-params))) 323 | (with-lsp-workspace workspace 324 | (lsp-request-async 325 | "query/subset" 326 | params 327 | (lambda (result) 328 | (lsp-mssql-with-result-buffer 329 | (goto-char (marker-position marker)) 330 | (insert "\n") 331 | (insert (lsp-mssql--render-table result)) 332 | (setq more-items-marker (copy-marker (point))) 333 | (insert "\n") 334 | (let ((start (point))) 335 | (render-load-more) 336 | (make-button 337 | start (point) 338 | 'action (lambda (&rest _) 339 | (interactive) 340 | (when-let ((params (subset-params))) 341 | (with-lsp-workspace workspace 342 | (lsp-request-async 343 | "query/subset" 344 | params 345 | (lambda (result) 346 | (lsp-mssql-with-result-buffer 347 | (goto-char (1- (marker-position more-items-marker))) 348 | (insert "\n") 349 | (insert (lsp-mssql--render-table result)) 350 | (org-table-align) 351 | (forward-line 1) 352 | (render-load-more) 353 | (run-hooks 'lsp-mssql-after-render-table-hook))) 354 | :mode 'detached)))) 355 | 'keymap (-doto (make-sparse-keymap) 356 | (define-key [M-return] 'push-button) 357 | (define-key [mouse-2] 'push-button)) 358 | 'help-echo "mouse-2, M-RET: Load more items.")) 359 | (insert "\n\n") 360 | (goto-char (marker-position marker)) 361 | (org-table-align) 362 | (display-buffer (current-buffer)) 363 | (run-hooks 'lsp-mssql-after-render-table-hook))) 364 | :mode 'detached)))))) 365 | 366 | (defun lsp-mssql--batch-complete (_workspace _params) 367 | "Hanler for batch complete.") 368 | 369 | (defun lsp-mssql--complete (_workspace _params) 370 | "Hanler for complete." 371 | (lsp-mssql-with-result-buffer)) 372 | 373 | (defvar-local lsp-mssql--markers (ht)) 374 | 375 | (defun lsp-mssql--batch-start (_workspace params) 376 | "Batch start handler. 377 | PARAMS batch handler params." 378 | (lsp-mssql-with-result-buffer 379 | (-let [(&hash "batchSummary" (&hash "executionStart" execution-start 380 | ;; "selection" (&hash "startColumn" 381 | ;; "startLine" 382 | ;; "endLine" 383 | ;; "endColumn") 384 | ;; "id" 385 | ) 386 | ;; "ownerUri" owner-uri 387 | ) params] 388 | ;; (insert (format "* Batch %s\n" id)) 389 | (lsp--info "%s Started execution" execution-start) 390 | ;; (insert "#+BEGIN_SRC sql\n") 391 | ;; (insert (with-current-buffer (find-buffer-visiting (lsp--uri-to-path owner-uri)) 392 | ;; (buffer-substring (lsp--position-to-point (ht ("line" startLine) 393 | ;; ("character" startColumn))) 394 | ;; (lsp--position-to-point (ht ("line" endLine) 395 | ;; ("character" endColumn)))))) 396 | ;; (insert "#+END_SRC\n\n") 397 | ) 398 | (display-buffer (current-buffer)))) 399 | 400 | (defun lsp-mssql--connection-changed (_workspace _params) 401 | "Hanler for batch complete.") 402 | 403 | (defun lsp-mssql--after-open-fn () 404 | "After open handler." 405 | (setq lsp-mssql-buffer-status (propertize "SQL Server disconnected" 406 | 'face 'warning 407 | 'local-map (make-mode-line-mouse-map 408 | 'mouse-1 'lsp-mssql-connect)))) 409 | (lsp-register-client 410 | (make-lsp-client :new-connection 411 | (lsp-stdio-connection 412 | (lambda () 413 | (let ((server (f-join lsp-mssql-download-location "MicrosoftSqlToolsServiceLayer"))) 414 | (if (executable-find server) 415 | (list server) 416 | (if (y-or-n-p "The mssql server is not present. Do you want to download it? ") 417 | (progn 418 | (lsp-mssql-download-server) 419 | (list server)) 420 | (user-error "Server is not installed? ")))))) 421 | :major-modes '(sql-mode) 422 | :priority -1 423 | :multi-root t 424 | :notification-handlers (ht ("objectexplorer/expandCompleted" #'lsp-mssql--expand-completed) 425 | ("objectexplorer/sessioncreated" 'lsp-mssql--session-created) 426 | ("connection/complete" #'lsp-mssql--connection-complete) 427 | ("connection/connectionchanged" 'lsp-mssql--connection-changed) 428 | ("telemetry/sqlevent" 'ignore) 429 | ("textDocument/intelliSenseReady" 'ignore) 430 | ("query/resultSetAvailable" 'lsp-mssql--result-set-available) 431 | ("query/message" 'lsp-mssql--message) 432 | ("query/resultSetUpdated" 'lsp-mssql--result-set-updated) 433 | ("query/resultSetComplete" 'lsp-mssql--result-set-complete) 434 | ("query/batchComplete" 'lsp-mssql--batch-complete) 435 | ("query/batchStart" 'lsp-mssql--batch-start) 436 | ("query/complete" 'lsp-mssql--complete)) 437 | :server-id 'sql 438 | :initialized-fn (lambda (workspace) 439 | (ht-clear lsp-mssql--connection-name->session-id) 440 | (puthash "explorer" (ht) (lsp--workspace-metadata workspace)) 441 | (with-lsp-workspace workspace 442 | (lsp--set-configuration (lsp-configuration-section "mssql")))) 443 | :after-open-fn #'lsp-mssql--after-open-fn)) 444 | 445 | (defun lsp-mssql-connect (connection) 446 | "Connect current buffer to a server using CONNECTION spec." 447 | (interactive (list (lsp--completing-read 448 | "Select connection: " 449 | (append lsp-mssql-connections nil) 450 | (lambda (connection) 451 | (plist-get connection :server)) 452 | nil 453 | t))) 454 | (lsp-request "connection/connect" 455 | `(:ownerUri ,(lsp--buffer-uri) 456 | :connection (:options ,connection)))) 457 | 458 | (defun lsp-mssql-disconnect () 459 | "Disconnect buffer from sql server." 460 | (interactive) 461 | (lsp-request "connection/disconnect" `(:ownerUri ,(lsp--buffer-uri))) 462 | (lsp-mssql--after-open-fn)) 463 | 464 | (defun lsp-mssql-execute-region (start end) 465 | "Execute selected region START to END." 466 | (interactive "r") 467 | (lsp-mssql-with-result-buffer 468 | (read-only-mode -1) 469 | (org-mode) 470 | (erase-buffer) 471 | (read-only-mode 1)) 472 | (-let (((&plist :line start-line 473 | :character start-character) (lsp--point-to-position start)) 474 | ((&plist :line end-line 475 | :character end-character) (lsp--point-to-position end))) 476 | (lsp-request 477 | "query/executeDocumentSelection" 478 | (list :ownerUri (lsp--buffer-uri) 479 | :querySelection (list :startLine start-line 480 | :startColumn start-character 481 | :endLine end-line 482 | :endColumn end-character))))) 483 | 484 | (defun lsp-mssql-execute-buffer () 485 | "Execute the SQL code in the buffer." 486 | (interactive) 487 | (lsp-mssql-with-result-buffer 488 | (read-only-mode -1) 489 | (org-mode) 490 | (erase-buffer) 491 | (read-only-mode 1)) 492 | (lsp-request "query/executeDocumentSelection" (list :ownerUri (lsp--buffer-uri)))) 493 | 494 | (defun lsp-mssql-cancel () 495 | "Cancel the current query." 496 | (interactive) 497 | (lsp-request "query/cancel" (list :ownerUri (lsp--buffer-uri)))) 498 | 499 | 500 | ;; object explorer 501 | 502 | (treemacs-modify-theme "Default" 503 | :icon-directory (f-join (f-dirname (or load-file-name buffer-file-name)) "images") 504 | :config 505 | (progn 506 | (treemacs-create-icon :file "AggregateFunction.png" :extensions (AggregateFunction) :fallback "-") 507 | (treemacs-create-icon :file "AggregateFunctionParameter_Input.png" :extensions (AggregateFunctionParameter_Input) :fallback "-") 508 | (treemacs-create-icon :file "AggregateFunctionParameter_Output.png" :extensions (AggregateFunctionParameter_Output) :fallback "-") 509 | (treemacs-create-icon :file "AggregateFunctionParameter_Return.png" :extensions (AggregateFunctionParameter_Return) :fallback "-") 510 | (treemacs-create-icon :file "ApplicationRole.png" :extensions (ApplicationRole) :fallback "-") 511 | (treemacs-create-icon :file "Assembly.png" :extensions (Assembly) :fallback "-") 512 | (treemacs-create-icon :file "AsymmetricKey.png" :extensions (AsymmetricKey) :fallback "-") 513 | (treemacs-create-icon :file "BrokerPriority.png" :extensions (BrokerPriority) :fallback "-") 514 | (treemacs-create-icon :file "Certificate.png" :extensions (Certificate) :fallback "-") 515 | (treemacs-create-icon :file "Column.png" :extensions (Column) :fallback "-") 516 | (treemacs-create-icon :file "ColumnEncryptionKey.png" :extensions (ColumnEncryptionKey) :fallback "-") 517 | (treemacs-create-icon :file "ColumnMasterKey.png" :extensions (ColumnMasterKey) :fallback "-") 518 | (treemacs-create-icon :file "Constraint.png" :extensions (Constraint) :fallback "-") 519 | (treemacs-create-icon :file "Contract.png" :extensions (Contract) :fallback "-") 520 | (treemacs-create-icon :file "Database.png" :extensions (Database) :fallback "-") 521 | (treemacs-create-icon :file "DatabaseAndQueueEventNotification.png" :extensions (DatabaseAndQueueEventNotification) :fallback "-") 522 | (treemacs-create-icon :file "DatabaseAuditSpecification.png" :extensions (DatabaseAuditSpecification) :fallback "-") 523 | (treemacs-create-icon :file "DatabaseEncryptionKey.png" :extensions (DatabaseEncryptionKey) :fallback "-") 524 | (treemacs-create-icon :file "DatabaseRole.png" :extensions (DatabaseRole) :fallback "-") 525 | (treemacs-create-icon :file "DatabaseScopedCredential.png" :extensions (DatabaseScopedCredential) :fallback "-") 526 | (treemacs-create-icon :file "DatabaseTrigger.png" :extensions (DatabaseTrigger) :fallback "-") 527 | (treemacs-create-icon :file "Database_Unavailable.png" :extensions (Database_Unavailable) :fallback "-") 528 | (treemacs-create-icon :file "DefaultIcon.png" :extensions (DefaultIcon) :fallback "-") 529 | (treemacs-create-icon :file "ExternalDataSource.png" :extensions (ExternalDataSource) :fallback "-") 530 | (treemacs-create-icon :file "ExternalFileFormat.png" :extensions (ExternalFileFormat) :fallback "-") 531 | (treemacs-create-icon :file "FileGroupFile.png" :extensions (FileGroupFile) :fallback "-") 532 | (treemacs-create-icon :file "Folder.png" :extensions (Folder) :fallback "-") 533 | (treemacs-create-icon :file "FullTextCatalog.png" :extensions (FullTextCatalog) :fallback "-") 534 | (treemacs-create-icon :file "FullTextStopList.png" :extensions (FullTextStopList) :fallback "-") 535 | (treemacs-create-icon :file "HDFSFolder.png" :extensions (HDFSFolder) :fallback "-") 536 | (treemacs-create-icon :file "Index.png" :extensions (Index) :fallback "-") 537 | (treemacs-create-icon :file "Key_ForeignKey.png" :extensions (Key_ForeignKey) :fallback "-") 538 | (treemacs-create-icon :file "Key_PrimaryKey.png" :extensions (Key_PrimaryKey) :fallback "-") 539 | (treemacs-create-icon :file "Key_UniqueKey.png" :extensions (Key_UniqueKey) :fallback "-") 540 | (treemacs-create-icon :file "MasterKey.png" :extensions (MasterKey) :fallback "-") 541 | (treemacs-create-icon :file "MessageType.png" :extensions (MessageType) :fallback "-") 542 | (treemacs-create-icon :file "PartitionFunction.png" :extensions (PartitionFunction) :fallback "-") 543 | (treemacs-create-icon :file "PartitionScheme.png" :extensions (PartitionScheme) :fallback "-") 544 | (treemacs-create-icon :file "Queue.png" :extensions (Queue) :fallback "-") 545 | (treemacs-create-icon :file "RemoteServiceBinding.png" :extensions (RemoteServiceBinding) :fallback "-") 546 | (treemacs-create-icon :file "Route.png" :extensions (Route) :fallback "-") 547 | (treemacs-create-icon :file "ScalarValuedFunction.png" :extensions (ScalarValuedFunction) :fallback "-") 548 | (treemacs-create-icon :file "ScalarValuedFunctionParameter_Input.png" :extensions (ScalarValuedFunctionParameter_Input) :fallback "-") 549 | (treemacs-create-icon :file "ScalarValuedFunctionParameter_Output.png" :extensions (ScalarValuedFunctionParameter_Output) :fallback "-") 550 | (treemacs-create-icon :file "ScalarValuedFunctionParameter_Return.png" :extensions (ScalarValuedFunctionParameter_Return) :fallback "-") 551 | (treemacs-create-icon :file "Schema.png" :extensions (Schema) :fallback "-") 552 | (treemacs-create-icon :file "SearchPropertyList.png" :extensions (SearchPropertyList) :fallback "-") 553 | (treemacs-create-icon :file "SecurityPolicy.png" :extensions (SecurityPolicy) :fallback "-") 554 | (treemacs-create-icon :file "Sequence.png" :extensions (Sequence) :fallback "-") 555 | (treemacs-create-icon :file "ServerLevelCredential.png" :extensions (ServerLevelCredential) :fallback "-") 556 | (treemacs-create-icon :file "ServerLevelCryptographicProvider.png" :extensions (ServerLevelCryptographicProvider) :fallback "-") 557 | (treemacs-create-icon :file "ServerLevelEndpoint.png" :extensions (ServerLevelEndpoint) :fallback "-") 558 | (treemacs-create-icon :file "ServerLevelLinkedServer.png" :extensions (ServerLevelLinkedServer) :fallback "-") 559 | (treemacs-create-icon :file "ServerLevelLinkedServerLogin.png" :extensions (ServerLevelLinkedServerLogin) :fallback "-") 560 | (treemacs-create-icon :file "ServerLevelLinkedServerLogin_Disabled.png" :extensions (ServerLevelLinkedServerLogin_Disabled) :fallback "-") 561 | (treemacs-create-icon :file "ServerLevelLogin.png" :extensions (ServerLevelLogin) :fallback "-") 562 | (treemacs-create-icon :file "ServerLevelLogin_Disabled.png" :extensions (ServerLevelLogin_Disabled) :fallback "-") 563 | (treemacs-create-icon :file "ServerLevelServerAudit.png" :extensions (ServerLevelServerAudit) :fallback "-") 564 | (treemacs-create-icon :file "ServerLevelServerAuditSpecification.png" :extensions (ServerLevelServerAuditSpecification) :fallback "-") 565 | (treemacs-create-icon :file "ServerLevelServerRole.png" :extensions (ServerLevelServerRole) :fallback "-") 566 | (treemacs-create-icon :file "ServerLevelServerTrigger.png" :extensions (ServerLevelServerTrigger) :fallback "-") 567 | (treemacs-create-icon :file "Server_green.png" :extensions (Server) :fallback "-") 568 | (treemacs-create-icon :file "Server_red.png" :extensions (Server_red) :fallback "-") 569 | (treemacs-create-icon :file "Service.png" :extensions (Service) :fallback "-") 570 | (treemacs-create-icon :file "SqlLogFile.png" :extensions (SqlLogFile) :fallback "-") 571 | (treemacs-create-icon :file "Statistic.png" :extensions (Statistic) :fallback "-") 572 | (treemacs-create-icon :file "StoredProcedure.png" :extensions (StoredProcedure) :fallback "-") 573 | (treemacs-create-icon :file "StoredProcedureParameter_Input.png" :extensions (StoredProcedureParameter_Input) :fallback "-") 574 | (treemacs-create-icon :file "StoredProcedureParameter_Output.png" :extensions (StoredProcedureParameter_Output) :fallback "-") 575 | (treemacs-create-icon :file "StoredProcedureParameter_Return.png" :extensions (StoredProcedureParameter_Return) :fallback "-") 576 | (treemacs-create-icon :file "SymmetricKey.png" :extensions (SymmetricKey) :fallback "-") 577 | (treemacs-create-icon :file "Synonym.png" :extensions (Synonym) :fallback "-") 578 | (treemacs-create-icon :file "SystemApproximateNumeric.png" :extensions (SystemApproximateNumeric) :fallback "-") 579 | (treemacs-create-icon :file "SystemBinaryString.png" :extensions (SystemBinaryString) :fallback "-") 580 | (treemacs-create-icon :file "SystemCharacterString.png" :extensions (SystemCharacterString) :fallback "-") 581 | (treemacs-create-icon :file "SystemClrDataType.png" :extensions (SystemClrDataType) :fallback "-") 582 | (treemacs-create-icon :file "SystemContract.png" :extensions (SystemContract) :fallback "-") 583 | (treemacs-create-icon :file "SystemDateAndTime.png" :extensions (SystemDateAndTime) :fallback "-") 584 | (treemacs-create-icon :file "SystemExactNumeric.png" :extensions (SystemExactNumeric) :fallback "-") 585 | (treemacs-create-icon :file "SystemMessageType.png" :extensions (SystemMessageType) :fallback "-") 586 | (treemacs-create-icon :file "SystemOtherDataType.png" :extensions (SystemOtherDataType) :fallback "-") 587 | (treemacs-create-icon :file "SystemQueue.png" :extensions (SystemQueue) :fallback "-") 588 | (treemacs-create-icon :file "SystemService.png" :extensions (SystemService) :fallback "-") 589 | (treemacs-create-icon :file "SystemSpatialDataType.png" :extensions (SystemSpatialDataType) :fallback "-") 590 | (treemacs-create-icon :file "SystemUnicodeCharacterString.png" :extensions (SystemUnicodeCharacterString) :fallback "-") 591 | (treemacs-create-icon :file "Table.png" :extensions (Table) :fallback "-") 592 | (treemacs-create-icon :file "TableValuedFunction.png" :extensions (TableValuedFunction) :fallback "-") 593 | (treemacs-create-icon :file "TableValuedFunctionParameter_Input.png" :extensions (TableValuedFunctionParameter_Input) :fallback "-") 594 | (treemacs-create-icon :file "TableValuedFunctionParameter_Output.png" :extensions (TableValuedFunctionParameter_Output) :fallback "-") 595 | (treemacs-create-icon :file "TableValuedFunctionParameter_Return.png" :extensions (TableValuedFunctionParameter_Return) :fallback "-") 596 | (treemacs-create-icon :file "Table_Temporal.png" :extensions (Table_Temporal) :fallback "-") 597 | (treemacs-create-icon :file "Trigger.png" :extensions (Trigger) :fallback "-") 598 | (treemacs-create-icon :file "Trigger_Disabled.png" :extensions (Trigger_Disabled) :fallback "-") 599 | (treemacs-create-icon :file "User.png" :extensions (User) :fallback "-") 600 | (treemacs-create-icon :file "UserDefinedDataType.png" :extensions (UserDefinedDataType) :fallback "-") 601 | (treemacs-create-icon :file "UserDefinedTableType.png" :extensions (UserDefinedTableType) :fallback "-") 602 | (treemacs-create-icon :file "UserDefinedTableTypeColumn.png" :extensions (UserDefinedTableTypeColumn) :fallback "-") 603 | (treemacs-create-icon :file "UserDefinedTableTypeConstraint.png" :extensions (UserDefinedTableTypeConstraint) :fallback "-") 604 | (treemacs-create-icon :file "UserDefinedType.png" :extensions (UserDefinedType) :fallback "-") 605 | (treemacs-create-icon :file "User_Disabled.png" :extensions (User_Disabled) :fallback "-") 606 | (treemacs-create-icon :file "View.png" :extensions (View) :fallback "-") 607 | (treemacs-create-icon :file "XmlSchemaCollection.png" :extensions (XmlSchemaCollection) :fallback "-") 608 | (treemacs-create-icon :file "add.png" :extensions (add) :fallback "-") 609 | (treemacs-create-icon :file "add_inverse.png" :extensions (add_inverse) :fallback "-"))) 610 | 611 | (defvar lsp-mssql-object-explorer-map 612 | (-doto (make-sparse-keymap) 613 | (define-key (kbd "R") #'lsp-mssql-object-explorer-refresh) 614 | (define-key (kbd "C") #'lsp-mssql-object-explorer-connect) 615 | (define-key (kbd "K") #'lsp-mssql-object-explorer-disconnect)) 616 | "Keymap for `lsp-mssql-object-explorer-mode'.") 617 | 618 | (define-minor-mode lsp-mssql-object-explorer-mode 619 | "Minor mode for SQL Object Explorer." 620 | nil nil lsp-mssql-object-explorer-map) 621 | 622 | (defun lsp-mssql-object-explorer-disconnect () 623 | "Disconnect placeholder." 624 | (interactive) 625 | (user-error "To be implemented? ")) 626 | 627 | (defun lsp-mssql-object-explorer-refresh () 628 | "Refresh object explorer." 629 | (interactive) 630 | (-let [(&plist :session-id :node-path) (button-get (treemacs-node-at-point) :item)] 631 | (with-lsp-workspace (lsp-find-workspace 'sql) 632 | (lsp-request "objectexplorer/refresh" 633 | `(:sessionId ,session-id :nodePath ,node-path))))) 634 | 635 | (defun lsp-mssql--to-node (nodes &optional session-id node) 636 | "Convert NODE to lsp-treemacs generic node. 637 | SESSION-ID - the session id. 638 | NODES - all nodes." 639 | (setq session-id (or session-id (gethash "sessionId" node))) 640 | 641 | (-let [(&hash "label" "nodeType" node-type "nodePath" node-path "isLeaf" leaf?) node] 642 | `(:label ,label 643 | :key ,label 644 | :icon ,(intern node-type) 645 | :node-path ,node-path 646 | :session-id ,session-id 647 | :actions ,(if (string= node-type "Server") 648 | '(["Refresh" lsp-mssql-object-explorer-refresh] 649 | ["Disconnect" lsp-mssql-object-explorer-disconnect]) 650 | '(["Refresh" lsp-mssql-object-explorer-refresh])) 651 | ,@(unless leaf? 652 | (list :children 653 | (lambda (_node) 654 | (let ((children (gethash (list node-path) nodes :empty))) 655 | (if (not (eq :empty children)) 656 | (-map (-partial #'lsp-mssql--to-node nodes session-id) children) 657 | (with-lsp-workspace (lsp-find-workspace 'sql nil) 658 | (lsp-request "objectexplorer/expand" 659 | `(:sessionId ,session-id :nodePath ,node-path)) 660 | nil))))))))) 661 | 662 | (defun lsp-mssql--show-explorer (tree title) 663 | "Show explorer. 664 | TREE is the data to display, TITLE will be used for the 665 | modeline in the result buffer." 666 | (with-current-buffer (get-buffer-create "*SQL Object explorer*") 667 | (lsp-treemacs-initialize) 668 | (setq-local lsp-treemacs-tree tree) 669 | (setq-local face-remapping-alist '((button . default))) 670 | (lsp-treemacs-generic-refresh) 671 | (display-buffer-in-side-window (current-buffer) '((side . right))) 672 | (setq-local mode-name title) 673 | (lsp-mssql-object-explorer-mode))) 674 | 675 | 676 | 677 | (defun lsp-mssql-object-explorer-connect (&rest _) 678 | "Open connection." 679 | (interactive) 680 | (-let [(connection &as &plist :server :user) (plist-get (button-get (treemacs-node-at-point) :item) :connection)] 681 | (with-lsp-workspace (lsp-find-workspace 'sql) 682 | (puthash 683 | (concat server " : " user) 684 | (gethash "sessionId" 685 | (lsp-request "objectexplorer/createsession" 686 | (list :options connection))) 687 | lsp-mssql--connection-name->session-id)))) 688 | 689 | (defun lsp-mssql-object-explorer () 690 | "Show server explorer." 691 | (interactive) 692 | (lsp-mssql--show-explorer 693 | (append 694 | (let ((all-nodes (-some->> (lsp-find-workspace 'sql nil) 695 | lsp--workspace-metadata 696 | (gethash "explorer")))) 697 | (->> all-nodes 698 | (ht->alist) 699 | (-keep (-lambda (((id . is-session?) . (node))) 700 | (when is-session? 701 | (lsp-mssql--to-node all-nodes id node)))))) 702 | (->> lsp-mssql-connections 703 | (seq-map 704 | (-lambda ((connection &as &plist :server :user)) 705 | (let ((connection-name (concat server " : " user))) 706 | (unless (gethash connection-name 707 | lsp-mssql--connection-name->session-id) 708 | `(:label ,connection-name 709 | :icon Server_red 710 | :key ,connection-name 711 | :connection ,connection 712 | :actions (["Connect" lsp-mssql-object-explorer-connect])))))) 713 | (seq-filter #'identity))) 714 | "*MSSQL Object Explorer*")) 715 | 716 | 717 | 718 | (provide 'lsp-mssql) 719 | ;;; lsp-mssql.el ends here 720 | --------------------------------------------------------------------------------