From 0aab18636d0bb5d0ca26fe94c8d437c563edf52e Mon Sep 17 00:00:00 2001 From: Dmitry Maslennikov Date: Sat, 20 Apr 2024 19:23:29 +1000 Subject: [PATCH] Support for filter --- .github/workflows/main.yml | 53 +++++++++++++------------------------ .vscode/launch.json | 3 ++- connection.schema.json | 9 +++++++ package.json | 5 ++-- src/ls/driver.ts | 8 ++++-- src/ls/queries.ts | 3 ++- test/project.code-workspace | 14 +++++----- 7 files changed, 48 insertions(+), 47 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6971110..3cc8239 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,7 +22,7 @@ jobs: # os: [ubuntu-latest, windows-latest, macOS-latest] os: [ubuntu-latest] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* - name: Set an output id: set-version @@ -46,18 +46,14 @@ jobs: echo $VERSION > .version echo $NAME > .name - name: Use Node.js - uses: actions/setup-node@v2 + uses: actions/setup-node@v4 with: - node-version: 14 + node-version: 20 - run: npm install - name: lint if: runner.os == 'Linux' run: npm run lint - run: npm run compile - - name: npm test - uses: GabrielBB/xvfb-action@v1.0 - with: - run: npm run test - name: Build package if: runner.os == 'Linux' run: | @@ -79,7 +75,7 @@ jobs: runs-on: ubuntu-latest needs: build steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v4 with: name: meta path: . @@ -90,48 +86,35 @@ jobs: set -x echo ::set-output name=version::`cat .version` echo ::set-output name=name::`cat .name` - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v4 with: name: ${{ steps.set-version.outputs.name }}.vsix - - name: Create Release - id: create_release - uses: actions/create-release@v1 - if: runner.os == 'Linux' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: v${{ steps.set-version.outputs.version }} - release_name: v${{ steps.set-version.outputs.version }} - prerelease: ${{ github.event_name != 'release' }} - body: | - Changes in this release - ${{ steps.set-version.outputs.changelog }} - name: Upload Release Asset id: upload-release-asset - uses: actions/upload-release-asset@v1 + uses: softprops/action-gh-release@v2 if: runner.os == 'Linux' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ${{ steps.set-version.outputs.name }}.vsix - asset_name: ${{ steps.set-version.outputs.name }}.vsix - asset_content_type: application/zip + tag_name: v${{ steps.set-version.outputs.version }} + prerelease: ${{ github.event_name != 'release' }} + files: ${{ steps.set-version.outputs.name }}.vsix + token: ${{ secrets.GITHUB_TOKEN }} publish: if: github.event_name == 'release' runs-on: ubuntu-latest needs: build steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: ref: master token: ${{ secrets.GITHUB_TOKEN }} - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v4 with: name: meta path: . - name: Use Node.js - uses: actions/setup-node@v2 + uses: actions/setup-node@v4 with: node-version: 14 - name: Prepare build @@ -155,15 +138,15 @@ jobs: npx vsce package -o ${{ steps.set-version.outputs.name }}.vsix - name: Upload Release Asset id: upload-release-asset - uses: actions/upload-release-asset@v1 + uses: softprops/action-gh-release@v2 if: runner.os == 'Linux' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - upload_url: ${{ github.event.release.upload_url }} - asset_path: ${{ steps.set-version.outputs.name }}.vsix - asset_name: ${{ steps.set-version.outputs.name }}.vsix - asset_content_type: application/zip + tag_name: v${{ steps.set-version.outputs.version }} + prerelease: ${{ github.event_name != 'release' }} + files: ${{ steps.set-version.outputs.name }}.vsix + token: ${{ secrets.GITHUB_TOKEN }} - name: Publish to VSCode Marketplace run: | [ -n "${{ secrets.VSCE_TOKEN }}" ] && \ diff --git a/.vscode/launch.json b/.vscode/launch.json index c00a266..5179d97 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,8 +9,9 @@ "${workspaceFolder}/test/project.code-workspace", "--extensionDevelopmentPath=${workspaceFolder}" ], + "sourceMaps": true, "outFiles": [ - "${workspaceFolder}/out/**/*.js" + "${workspaceFolder}/dist/**/*.js" ], "preLaunchTask": "npm: webpack" } diff --git a/connection.schema.json b/connection.schema.json index bff3098..6ea383c 100644 --- a/connection.schema.json +++ b/connection.schema.json @@ -37,6 +37,15 @@ "title": "Show system items?", "type": "boolean", "default": false + }, + "filter": { + "title": "Filter", + "type": "string", + "examples": [ + "'Ens*", + "'HS*" + ], + "description": "* 0 or more characters, _ any one character, ' NOT pattern" } }, "dependencies": { diff --git a/package.json b/package.json index b0076a3..923384b 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,8 @@ "compile": "tsc -p ./", "watch": "tsc -watch -p ./", "package": "vsce package -o sqltools-intersystems-driver.vsix", - "lint": "" + "lint": "", + "test": "" }, "keywords": [ "intersystems-iris-driver", @@ -48,7 +49,7 @@ "mtxr.sqltools" ], "activationEvents": [ - "*", + "onStartupFinished", "onLanguage:sql", "onCommand:sqltools.*" ], diff --git a/src/ls/driver.ts b/src/ls/driver.ts index 31240c7..bab4859 100644 --- a/src/ls/driver.ts +++ b/src/ls/driver.ts @@ -13,6 +13,7 @@ export default class IRISDriver extends AbstractDriver im queries: IQueries = queries; private showSystem = false; + private filter = ""; public async open() { if (this.connection) { @@ -22,6 +23,7 @@ export default class IRISDriver extends AbstractDriver im const { namespace } = this.credentials; let config: IRISDirect; this.showSystem = this.credentials.showSystem || false; + this.filter = this.credentials.filter || ""; if (this.credentials.serverName) { throw new Error("not supported"); @@ -113,6 +115,7 @@ export default class IRISDriver extends AbstractDriver im private async getSchemas({ item }: Arg0) { item['showSystem'] = this.showSystem; + item['filter'] = this.filter; switch (item.childType) { case ContextValue.TABLE: @@ -127,6 +130,7 @@ export default class IRISDriver extends AbstractDriver im private async getChildrenForSchema({ item }: Arg0) { item['showSystem'] = this.showSystem; + item['filter'] = this.filter; switch (item.childType) { case ContextValue.TABLE: @@ -151,11 +155,11 @@ export default class IRISDriver extends AbstractDriver im case ContextValue.DATABASE: // Syntatically, a schema in IRIS SQL resembles a database in other databases. // That's the simplest way to adapt IRIS SQL to the generic Hue parser vscode-sqltools uses. - return this.queryResults(this.queries.searchEverything({ search, showSystem: this.showSystem })); + return this.queryResults(this.queries.searchEverything({ search, showSystem: this.showSystem, filter: this.filter })); case ContextValue.TABLE: case ContextValue.FUNCTION: case ContextValue.VIEW: - const searchParams = { search, showSystem: this.showSystem, itemType, ...extraParams }; + const searchParams = { search, showSystem: this.showSystem, filter: this.filter, itemType, ...extraParams }; if (extraParams['database']) { searchParams['schema'] = extraParams['database']; } diff --git a/src/ls/queries.ts b/src/ls/queries.ts index a8a0ea7..d1ea9a1 100644 --- a/src/ls/queries.ts +++ b/src/ls/queries.ts @@ -14,6 +14,7 @@ ValueColumn[ContextValue.FUNCTION] = "PROCEDURE_NAME"; interface ISchema extends NSDatabase.ISchema { showSystem: boolean; + filter: string; } const describeTable: IQueries['describeTable'] = queryFactory` @@ -173,7 +174,7 @@ DISTINCT BY(SCHEMA_NAME) '${ContextValue.SCHEMA}' as "type", '${type}' as "childType", 'folder' as iconId -FROM ${Functions[type]} (${p => p.showSystem ? 1 : 0}) +FROM ${Functions[type]} (${p => p.showSystem ? 1 : 0}, '${p => (p.filter && p.filter != "") ? `${p.filter.replace("'", "''")}` : "*"}') `; const fetchTableSchemas = fetchTypedSchemas(ContextValue.TABLE); diff --git a/test/project.code-workspace b/test/project.code-workspace index 8efbd19..8bf3d7a 100644 --- a/test/project.code-workspace +++ b/test/project.code-workspace @@ -42,16 +42,18 @@ "username": "_SYSTEM" }, { - "askForPassword": false, + "namespace": "USER", "connectionMethod": "Server and Port", + "showSystem": false, + "filter": "'Ens*", + "previewLimit": 50, + "server": "localhost", + "port": 52773, + "https": false, + "askForPassword": false, "driver": "InterSystems IRIS", "name": "InterSystems IRIS", - "namespace": "USER", "password": "SYS", - "port": 52773, - "previewLimit": 50, - "server": "localhost", - "showSystem": true, "username": "_SYSTEM" } ]