diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0a74204..0c5f08a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,41 +1,22 @@ name: build on: push: - branches: - - master pull_request: branches: - master jobs: package: - runs-on: ubuntu-20.04 - defaults: - run: - shell: nix develop -c bash {0} + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 - with: - submodules: true - - uses: cachix/install-nix-action@v16 - # TODO: implement build cache - - run: npm ci - - run: ./compile_sqls.fish - - run: npx vsce package --out sqlnotebook-${{ github.sha }}.vsix + - uses: DeterminateSystems/nix-installer-action@v4 + - uses: DeterminateSystems/magic-nix-cache-action@v2 + - run: nix build + - name: Prepare to upload + run: cp ./result/* sqlnotebook-${{ github.sha }}.vsix - name: Upload vsix as artifact uses: actions/upload-artifact@v1 with: name: sqlnotebook-${{ github.sha }}.vsix path: sqlnotebook-${{ github.sha }}.vsix - test: - runs-on: ubuntu-20.04 - defaults: - run: - shell: nix develop -c bash {0} - steps: - - uses: actions/checkout@v3 - with: - submodules: true - - uses: cachix/install-nix-action@v16 - - run: npm ci - - run: npm run lint diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4c2b929..d6a7a73 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -5,20 +5,16 @@ on: jobs: publish: - runs-on: ubuntu-latest - defaults: - run: - shell: nix develop -c bash {0} + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 - with: - submodules: true - - uses: cachix/install-nix-action@v16 + - uses: DeterminateSystems/nix-installer-action@v4 + - uses: DeterminateSystems/magic-nix-cache-action@v2 - name: Parse version run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - - run: npm ci - - run: ./compile_sqls.fish - - run: npx vsce package --out sqlnotebook-${{ env.RELEASE_VERSION }}.vsix + - run: nix build + - name: Prepare to upload + run: cp ./result/* sqlnotebook-${{ env.RELEASE_VERSION }}.vsix - name: Upload vsix as artifact uses: actions/upload-artifact@v1 with: diff --git a/README.md b/README.md index 06b9b7f..f2c09e1 100644 --- a/README.md +++ b/README.md @@ -27,3 +27,12 @@ Open any `.sql` file with the `Open With` menu option. Then, select the `SQL Not ![Screen Shot 2021-12-30 at 1 30 39 PM](https://user-images.githubusercontent.com/7585078/147782929-f9b7846b-6911-45ed-8354-ff0130a912b1.png) ![Screen Shot 2021-12-30 at 1 34 32 PM](https://user-images.githubusercontent.com/7585078/147782853-c0ea8ecb-e5f7-410f-83c2-af3d0562302e.png) + +## FAQ + +**If the file is stored as a regular `.sql` file, how are cell boundaries detected?** + +Cell boundaries are inferred from the presence of two consecutive empty lines. + +Note: this can pose issues with certain code formatters. You will need to +configure them to respect consecutive newlines. diff --git a/compile_sqls.fish b/compile_sqls.fish deleted file mode 100755 index 9c88780..0000000 --- a/compile_sqls.fish +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env fish - -# This script compiles the ./sqls language server -# into binaries for the most common ARCH/OS combinations. -# Then, we use `upx` to compress the binary to save on -# overall bundle size. -# -# Eventually, these binaries are bundled into the final -# .vsix asset and shipped with the extension. At runtime, -# the extension will check if an available binary exists for -# the given detected ARCH/OS combo. If yes, it will run it as -# a language server to provide enhanced completion support. - - -set --local arch { arm64, amd64, 386 } -set --local os { linux, darwin, windows } - -cd sqls - -for a in $arch - for o in $os - if [ "$o" = "darwin" -a "$a" = "386" ] - continue - end - echo "building sqls_"$a"_"$o - set --local binpath "../sqls_bin/sqls_"$a"_"$o - CGO_ENABLED=0 GOOS=$o GOARCH=$a go build -o $binpath -ldflags="-s -w"; or exit 1 - - # disable this for now, it was causing issues on arm64/darwin - # upx $binpath - end -end diff --git a/flake.lock b/flake.lock index c566578..15895dd 100644 --- a/flake.lock +++ b/flake.lock @@ -17,11 +17,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1647350163, - "narHash": "sha256-OcMI+PFEHTONthXuEQNddt16Ml7qGvanL3x8QOl2Aao=", + "lastModified": 1690720142, + "narHash": "sha256-GywuiZjBKfFkntQwpNQfL+Ksa2iGjPprBGL0/psgRZM=", "owner": "nixos", "repo": "nixpkgs", - "rev": "3eb07eeafb52bcbf02ce800f032f18d666a9498d", + "rev": "3acb5c4264c490e7714d503c7166a3fde0c51324", "type": "github" }, "original": { @@ -31,10 +31,27 @@ "type": "github" } }, + "npmlock2nix": { + "flake": false, + "locked": { + "lastModified": 1673447413, + "narHash": "sha256-sJM82Sj8yfQYs9axEmGZ9Evzdv/kDcI9sddqJ45frrU=", + "owner": "nix-community", + "repo": "npmlock2nix", + "rev": "9197bbf397d76059a76310523d45df10d2e4ca81", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "npmlock2nix", + "type": "github" + } + }, "root": { "inputs": { "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "npmlock2nix": "npmlock2nix" } } }, diff --git a/flake.nix b/flake.nix index 0e550c9..86f359e 100644 --- a/flake.nix +++ b/flake.nix @@ -3,20 +3,65 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; flake-utils.url = "github:numtide/flake-utils"; + npmlock2nix = { + url = "github:nix-community/npmlock2nix"; + flake = false; + }; }; - outputs = { self, nixpkgs, flake-utils }: + outputs = { self, nixpkgs, npmlock2nix, flake-utils }: flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; + npm2nix = import npmlock2nix { inherit pkgs; }; + sqls = { arch, os }: with pkgs; (buildGoModule { + name = "sqls_${arch}_${os}"; + src = fetchFromGitHub { + owner = "cmoog"; + repo = "sqls"; + rev = "8f600074d1b0778c7a0b6b9b820dd4d2d05fbdee"; + sha256 = "sha256-3nYWMDKqmQ0NnflX/4vx1BA+rubWV7pRdZcDaKUatO0="; + }; + doCheck = false; + vendorHash = "sha256-Xv/LtjwgxydMwychQtW1+quqUbkC5PVzhga5qT5lI3s="; + CGO_ENABLED = 0; + }).overrideAttrs (old: old // { GOOS = os; GOARCH = arch; }); + # build each os/arch combination + sqlsInstallCommands = builtins.concatStringsSep "\n" (pkgs.lib.flatten (map + (os: (map + (arch: + # skip this invalid os/arch combination + if arch == "386" && os == "darwin" then "" else + "cp $(find ${sqls { inherit os arch; }} -type f) $out/bin/sqls_${arch}_${os}" + ) [ "amd64" "arm64" "386" ])) [ "linux" "darwin" "windows" ])); + sqlsBins = pkgs.runCommand "multiarch-sqls" { } '' + mkdir -p $out/bin + ${sqlsInstallCommands} + ''; in { formatter = pkgs.nixpkgs-fmt; + packages = { + inherit sqlsBins; + default = npm2nix.v2.build { + src = pkgs.runCommand "src-with-sqls" { } '' + mkdir $out + cp -r ${./.}/* $out + cp -r ${sqlsBins}/bin $out/sqls_bin + ''; + nodejs = pkgs.nodejs; + buildCommands = [ "npm run build" ]; + installPhase = '' + mkdir -p $out + cp *.vsix $out/ + ''; + }; + }; devShells.default = pkgs.mkShell { packages = with pkgs; [ fish - go_1_17 - nodejs-16_x + go + nodejs typos upx ]; diff --git a/src/serializer.ts b/src/serializer.ts index 3c652c1..bd331d2 100644 --- a/src/serializer.ts +++ b/src/serializer.ts @@ -1,6 +1,9 @@ import { TextDecoder, TextEncoder } from 'util'; import * as vscode from 'vscode'; +// Cell block delimiter +const DELIMITER = '\n\n'; + export class SQLSerializer implements vscode.NotebookSerializer { async deserializeNotebook( context: Uint8Array, @@ -42,14 +45,14 @@ export class SQLSerializer implements vscode.NotebookSerializer { ? value : `/*markdown\n${value}\n*/` ) - .join('\n\n') + .join(DELIMITER) ); } } function splitSqlBlocks(raw: string): string[] { const blocks = []; - for (const block of raw.split('\n\n')) { + for (const block of raw.split(DELIMITER)) { if (block.trim().length > 0) { blocks.push(block); continue;