Skip to content

Commit 80ca50e

Browse files
fix: allow global strategy regardless of package.json (#33)
1 parent 5673511 commit 80ca50e

File tree

5 files changed

+31
-22
lines changed

5 files changed

+31
-22
lines changed

README.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ The [Language Server Protocol](https://microsoft.github.io/language-server-proto
1313
**First**, you need the LSP server binary. The [Postgres language server](https://github.com/supabase-community/postgres-language-server) is written in Rust and is therefore compiled to various binaries for various machines. You can set it up via one of five strategies. The extensions will check them in the following order:
1414

1515
- The `postgrestools.bin` VSCode setting can point to a binary with relative or absolute paths. You can use this if you want to download a specific binary from one of the [Postgres language server](https://github.com/supabase-community/postgres-language-server) releases and place it in your project.
16-
- **Recommended**: If you use node, you can simply run `npm i -D @postgrestools/postgrestools`. Once you restart the extension, it should look for the server binary in your `node_modules`.
16+
- **Recommended**: If you use node, you can simply run `npm i -D @postgrestools/postgrestools@latest`. Once you restart the extension, it should look for the server binary in your `node_modules`.
1717
- If you use node but you install your packages via Yarn Plug'n'Play, you can still install `@postgrestools/postgrestools`, and the extension will check your `.pnp.cjs` file for a binary.
1818
- You can install the LSP server globally (e.g. via `brew` or by downloading a binary from the GitHub releases). Make sure that its binary is exposed in your $PATH – the extension will search it for a `postgrestools` on Darwin/Linux or a `postgrestools.exe` on Windows.
19-
- If no LSP server binary can be found via the above strategies, **and you have no `package.json` at the root of your repository**, you will be prompted to download a binary from `postgrestools`'s Github Releases. You can also do this later via the [Download Server Command](#useful-commands). Note that the above strategies will still take precedence.
20-
21-
The found binary is copied to a temporary location in your VS Code extensions folder and run from there. When you restart the extension, the copied binary will be used, and the above places won't be searched.
19+
- If no LSP server binary can be found via the above strategies, you will be prompted to download a binary from `postgrestools`'s GitHub Releases. You can also do this later via the [Download Server Command](#useful-commands). Note that the above strategies will still take precedence.
20+
The found binary is copied to a temporary location in your VS Code extensions folder and run from there. When you restart the extension, the copied binary will be used, and the above places won't be searched.
2221

2322
## Setting Up Your Project
2423

@@ -65,6 +64,26 @@ The extension adds six commands to your VS Code Command Palette. They are all pr
6564
1. First, try restarting the extension via the `PostgresTools: Hard Reset (...)` command mentioned above.
6665
2. Open your VS Code Terminal, select the tab `Output`, and select one of the `postgrestools` extensions on the right. You might see what went wrong in the logs.
6766

67+
## FAQ
68+
69+
### I've installed the package via NPM but getting an `Error: Cannot find module '@postgrestools/cli-x86_64-windows-msvc/postgrestools.exe'`.
70+
71+
The platform-specific package is installed as an `optionalDependency`. If it can't be installed for whatever reason, `npm` won't complain. It's likely that something went wrong during the installation.
72+
73+
Another known issue is that npm installs the optional dependency at an unexpected location. It _should_ be located at `node_modules/@postgrestools/cli-aarch64-apple-darwin` (or another platform-specific package).
74+
75+
If you can't find the platform specific package, please just rerun `npm install` a couple of times.
76+
77+
If that still doesn't help, run `npm uninstall @postgrestools/postgrestools` and use the download server strategy mentioned [here.](#setting-up-the-lsp-server)
78+
79+
### Why am I prompted to install the PostgresTools binary?
80+
81+
You will only be prompted if all other [strategies](#setting-up-the-lsp-server) fail. If you set out to use a different strategy, make sure the binary/node package is actually at the expected location:
82+
83+
- Using the `postgrestool.bin` setting -> Is the binary at the configured location?
84+
- Using `npm` or `yarn` -> Are the `node_modules` installed correctly?
85+
- Using the `PATH` environment variable -> Can you run `$ postgrestools --version`, is the binary at the expected location?
86+
6887
## Issues
6988

7089
If you experience any issues, please report them at the [postgres language server](https://github.com/supabase-community/postgres-language-server) repository – we'll most frequently read issues there.

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "postgrestools",
33
"publisher": "Supabase",
44
"description": "Postgres Language Server right in your IDE.",
5-
"version": "1.1.6",
5+
"version": "1.1.7",
66
"repository": {
77
"type": "git",
88
"url": "https://github.com/supabase-community/postgrestools-vscode"

src/binary-finder-strategies.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ export const downloadPgltStrategy: BinaryFindStrategy = {
292292

293293
const proceed =
294294
(await window.showInformationMessage(
295-
"You've opened a supported file outside of a PostgresTools project, and no installed PostgresTools binary could not be found on your system. Would you like to download and install PostgresTools?",
295+
"You've opened a supported file outside of a PostgresTools project, and no installed PostgresTools binary could be found on your system. Would you like to download and install PostgresTools?",
296296
"Download and install",
297297
"No"
298298
)) === "Download and install";

src/binary-finder.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,6 @@ const LOCAL_STRATEGIES: Strategy[] = [
5050
logger.debug(`Found downloaded binary`, {
5151
path: uri.fsPath,
5252
}),
53-
54-
/**
55-
* We don't want to encourage users downloading the binary if they
56-
* could also install it via `npm` (or other Node package managers).
57-
*/
58-
condition: async (path) =>
59-
!path || // `path` should never be falsy in a local strategy
60-
workspace
61-
.findFiles(new RelativePattern(path, "**/package.json"))
62-
.then((rs) => rs.length === 0),
6353
},
6454
];
6555

0 commit comments

Comments
 (0)