Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ls): preview features regex #1742

Merged
merged 4 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/language-server/src/__test__/completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ describe('Completions', function () {
schema: /* Prisma */ `
generator client {
provider = "prisma-client-js"
previewFeatures = ["views"]
// ! Assures we are reading the correct previewFeatures section.
// previewFeatures = []
previewFeatures = ["views"]
}
|
`,
Expand Down
20 changes: 12 additions & 8 deletions packages/language-server/src/lib/ast/configBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ export function getFirstDatasourceProvider(schema: PrismaSchema): string | undef
}

export function getAllPreviewFeaturesFromGenerators(schema: PrismaSchema): PreviewFeatures[] | undefined {
// matches any `previewFeatures = [x]` in any position
// thanks to https://regex101.com for the online scratchpad
const previewFeaturesRegex = /previewFeatures\s=\s(\[.*\])/g
/**
* ```prisma
* generator client {
* provider = "prisma-client-js"
* // previewFeatures = [] // This will be ignored
* previewFeatures = ["views"]
* }
* ```
*
* ? for more info: https://regex101.com/r/ezoTU2/2
*/
const previewFeaturesRegex = /^\s*(?!\/\/\s)previewFeatures\s*=\s*(\[.*\])/m

// we could match against all the `previewFeatures = [x]` (could be that there is more than one?)
// var matchAll = text.matchAll(regexp)
// for (const match of matchAll) {
// console.log(match);
// }
const result = schema.findWithRegex(previewFeaturesRegex)

if (!result || !result.match[1]) {
Expand Down
Loading