Skip to content

Commit

Permalink
feat(ls): suggest SQL Server index clustered and values
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolg42 committed Jun 21, 2022
1 parent 250d806 commit bc914b2
Show file tree
Hide file tree
Showing 3 changed files with 366 additions and 131 deletions.
213 changes: 180 additions & 33 deletions packages/language-server/src/__test__/completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,35 @@ items.length`,
}

suite('Completions', function () {
// used both in generator and datasource
// used in more than 1 suite
const fieldProvider = {
label: 'provider',
kind: CompletionItemKind.Field,
}
const staticValueTrue = {
label: 'true',
kind: CompletionItemKind.Value,
}
const staticValueFalse = {
label: 'false',
kind: CompletionItemKind.Value,
}
const fieldsProperty = {
label: 'fields',
kind: CompletionItemKind.Property,
}
const mapProperty = {
label: 'map',
kind: CompletionItemKind.Property,
}
const sortProperty = {
label: 'sort',
kind: CompletionItemKind.Property,
}
const nameProperty = {
label: 'name',
kind: CompletionItemKind.Property,
}

suite('BASE BLOCKS', () => {
test('Diagnoses block type suggestions for empty file', () => {
Expand Down Expand Up @@ -413,14 +437,6 @@ suite('Completions', function () {
label: '@@ignore',
kind: CompletionItemKind.Property,
}
const fieldsProperty = {
label: 'fields',
kind: CompletionItemKind.Property,
}
const mapProperty = {
label: 'map',
kind: CompletionItemKind.Property,
}
const typeProperty = {
label: 'type',
kind: CompletionItemKind.Property,
Expand Down Expand Up @@ -1697,14 +1713,6 @@ suite('Completions', function () {
label: 'dbgenerated("")',
kind: CompletionItemKind.Function,
}
const staticValueTrue = {
label: 'true',
kind: CompletionItemKind.Value,
}
const staticValueFalse = {
label: 'false',
kind: CompletionItemKind.Value,
}
const enumValueOne = {
label: 'ADMIN',
kind: CompletionItemKind.Value,
Expand All @@ -1714,10 +1722,6 @@ suite('Completions', function () {
kind: CompletionItemKind.Value,
}

const fieldsProperty = {
label: 'fields',
kind: CompletionItemKind.Property,
}
const referencesProperty = {
label: 'references',
kind: CompletionItemKind.Property,
Expand All @@ -1734,18 +1738,6 @@ suite('Completions', function () {
label: '""',
kind: CompletionItemKind.Property,
}
const nameProperty = {
label: 'name',
kind: CompletionItemKind.Property,
}
const mapProperty = {
label: 'map',
kind: CompletionItemKind.Property,
}
const sortProperty = {
label: 'sort',
kind: CompletionItemKind.Property,
}
const lengthProperty = {
label: 'length',
kind: CompletionItemKind.Property,
Expand Down Expand Up @@ -2923,4 +2915,159 @@ suite('Completions', function () {
})
})
})

suite('SQL Server: clustered', () => {
const clusteredProperty = {
label: 'clustered',
kind: CompletionItemKind.Property,
}

/*
* Block attributes
*/
test('@@index([slug], |)', () => {
assertCompletion({
provider: 'sqlserver',
schema: /* Prisma */ `
model Post {
slug String @unique() @db.VarChar(3000)
@@index([slug], |)
}`,
expected: {
isIncomplete: false,
items: [fieldsProperty, mapProperty, clusteredProperty],
},
})
})
test('@@id([slug], |)', () => {
assertCompletion({
provider: 'sqlserver',
schema: /* Prisma */ `
model Post {
slug String @unique() @db.VarChar(3000)
@@id([slug], |)
}`,
expected: {
isIncomplete: false,
items: [fieldsProperty, nameProperty, mapProperty, clusteredProperty],
},
})
})
test('@@unique([slug], |)', () => {
assertCompletion({
provider: 'sqlserver',
schema: /* Prisma */ `
model Post {
slug String @unique() @db.VarChar(3000)
@@unique([slug], |)
}`,
expected: {
isIncomplete: false,
items: [fieldsProperty, nameProperty, mapProperty, clusteredProperty],
},
})
})

/*
* Field attributes
*/
test('@id(|)', () => {
assertCompletion({
provider: 'sqlserver',
schema: /* Prisma */ `
model Post {
unique Int @id(|)
}`,
expected: {
isIncomplete: false,
items: [mapProperty, sortProperty, clusteredProperty],
},
})
})
test('@unique(|)', () => {
assertCompletion({
provider: 'sqlserver',
schema: /* Prisma */ `
model Post {
slug String @unique(|) @db.VarChar(3000)
}`,
expected: {
isIncomplete: false,
items: [mapProperty, sortProperty, clusteredProperty],
},
})
})

/*
* Values
*/
test('@id(clustered: |)', () => {
assertCompletion({
provider: 'sqlserver',
schema: /* Prisma */ `
model Post {
unique Int @id(clustered: |)
}`,
expected: {
isIncomplete: false,
items: [staticValueTrue, staticValueFalse],
},
})
})
test('@unique(clustered: |)', () => {
assertCompletion({
provider: 'sqlserver',
schema: /* Prisma */ `
model Post {
slug String @unique(clustered: |) @db.VarChar(3000)
}`,
expected: {
isIncomplete: false,
items: [staticValueTrue, staticValueFalse],
},
})
})
test('@@index([slug], clustered: |)', () => {
assertCompletion({
provider: 'sqlserver',
schema: /* Prisma */ `
model Post {
slug String @unique() @db.VarChar(3000)
@@index([slug], clustered: |)
}`,
expected: {
isIncomplete: false,
items: [staticValueTrue, staticValueFalse],
},
})
})
test('@@id([slug], clustered: |)', () => {
assertCompletion({
provider: 'sqlserver',
schema: /* Prisma */ `
model Post {
slug String @unique() @db.VarChar(3000)
@@id([slug], clustered: |)
}`,
expected: {
isIncomplete: false,
items: [staticValueTrue, staticValueFalse],
},
})
})
test('@@unique([slug], clustered: |)', () => {
assertCompletion({
provider: 'sqlserver',
schema: /* Prisma */ `
model Post {
slug String @unique() @db.VarChar(3000)
@@unique([slug], clustered: |)
}`,
expected: {
isIncomplete: false,
items: [staticValueTrue, staticValueFalse],
},
})
})
})
})

0 comments on commit bc914b2

Please sign in to comment.