Skip to content

Commit 28f5fa6

Browse files
DruueJolg42
andauthored
fix(ls): preview features regex (#1742)
* fix #1741 * Make preview features regex more tolerant of spacing --------- Co-authored-by: Joël Galeran <[email protected]>
1 parent 0e0e9d1 commit 28f5fa6

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

packages/language-server/src/__test__/completion.test.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ describe('Completions', function () {
202202
schema: /* Prisma */ `
203203
generator client {
204204
provider = "prisma-client-js"
205-
previewFeatures = ["views"]
205+
// ! Assures we are reading the correct previewFeatures section.
206+
// previewFeatures = []
207+
previewFeatures = ["views"]
206208
}
207209
|
208210
`,

packages/language-server/src/lib/ast/configBlock.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,19 @@ export function getFirstDatasourceProvider(schema: PrismaSchema): string | undef
3232
}
3333

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

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

4650
if (!result || !result.match[1]) {

0 commit comments

Comments
 (0)