Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Postgres Language Server: JS + TS Template Literal Support#25

karlhorky started this conversation inIdeas
Discussion options

Originally opened as issue and a discussion in the organization repo (probably the wrong locations):


Hi there 👋 First of all, thanks for all of the effort that Supabase is putting into the PostgreSQL community, including tooling, really amazing 🙌

I recently encountered Postgres Language Server viathe recent tweet from@kiwicopple and it looks amazing!

I have been chasing the "holy grail" of tooling for SQL template literals in JavaScript + TypeScript for a while now:

Wasn't even looking for inline documentation yet, but that's a great addition too!

It seems that the plan will be for Postgres Language Server to support all of these use cases, which is amazing!

I would love to have everything handled by one highly-battle-tested tool, which could maybe also deal with some of the shortcomings from the tools listed above.

However, for Postgres Language Server to work for any of our projects, it would need a feature which I'm not sure it currently has (can't tell, from a quick glance at the docs and the code):

  • Support for tagged template literals in JavaScript and TypeScript

There is precedent for SQL tagged template literals in JS+TS, some of the more popular ones being:

Eg. I would love for all of the features of Postgres Language Server to be available in the following code block:

import{createClient}from'@vercel/postgres';asyncfunctionqueryPosts(){constclient=createClient();awaitclient.connect();try{constlikes=100;const{ rows, fields}=awaitclient.sql`SELECT * FROM posts WHERE likes >${likes};`;}finally{awaitclient.end();}}

Or this code block:

// db.jsimportpostgresfrom'postgres'constsql=postgres({/* options */})// will use psql environment variablesasyncfunctiongetUsersOver(age){constusers=awaitsql`    select      name,      age    from users    where age >${age}  `// users = Result [{ name: "Walter", age: 80 }, { name: 'Murray', age: 68 }, ...]returnusers}asyncfunctioninsertUser({ name, age}){constusers=awaitsql`    insert into users      (name, age)    values      (${name},${age})    returning name, age  `// users = Result [{ name: "Murray", age: 68 }]returnusers}
You must be logged in to vote

Replies: 3 comments 4 replies

Comment options

hey@karlhorky, sorry for the late reply!

I have been doing some research on this in the meanwhile and it seems like that it's the client who has to support multiple language servers for a single file. You can find a related discussionhere. for vscode as a client it is describedhere. I also found aneovim plugi that implements something similar. In summary, it will require some changes to the typescript plugin / extension. I am quite surprised myself that almost all editors (exception being Jetbrains products) only support a single language server per file.

You must be logged in to vote
0 replies
Comment options

This would be amazing

It's possible to add completions for SQL inside Typescript and Js files with a typescript plugin, this is an example:https://github.com/runem/lit-analyzer

(notice that there is another similar extension but autocompletion is not working there)

You must be logged in to vote
4 replies
@karlhorky
Comment options

Nice find! I guess this works viats-lit-plugin created by@runem and co-maintained by@rictic:

Typescript plugin that adds type checking and code completion to lit-html

@karlhorky
Comment options

Oh I also found one that does completions inside SQL inside of tagged template literals in JS/TS, by@xialvjun and@darky:

@remorses
Comment options

Nolit-analyzer is different fromts-lit-plugin, as i said completions ints-lit-plugin don't work

Alsolit-analyzer has the same interface as a typical LSP so it should be easy to use as starting point

@karlhorky
Comment options

Ah do you meancompletionsAtOffset() inpackages/lit-analyzer/src/lib/analyze/document-analyzer/html/completion/completions-at-offset.ts? I'm not as familiar as I would like to be with LSPs...

Comment options

I'm not sure if that helps, butVolar.js simplifies handlingembedded languages.

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Ideas
Labels
None yet
4 participants
@karlhorky@hatemhosny@psteinroe@remorses

[8]ページ先頭

©2009-2025 Movatter.jp