Skip to content

Commit

Permalink
feat(ls): suggest SQL Server index clustered and values (#1175)
Browse files Browse the repository at this point in the history
* feat(ls): suggest SQL Server index `clustered` and values

Closes #1138

Related https://www.prisma.io/docs/concepts/components/prisma-schema/indexes#configuring-if-indexes-are-clustered-or-non-clustered-with-clustered-sql-server

* Update packages/language-server/src/completion/completionUtils.ts

* cleanup
  • Loading branch information
Jolg42 committed Jun 21, 2022
1 parent 2936f5e commit b1c9c47
Show file tree
Hide file tree
Showing 3 changed files with 384 additions and 139 deletions.
223 changes: 188 additions & 35 deletions packages/language-server/src/__test__/completion.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { TextDocument } from 'vscode-languageserver-textdocument'
import { handleCompletionRequest } from '../MessageHandler'
import { CompletionList, CompletionParams, Position, CompletionItemKind } from 'vscode-languageserver'
import {
CompletionList,
CompletionParams,
Position,
CompletionItemKind,
CompletionTriggerKind,
} from 'vscode-languageserver'
import assert from 'assert'
import dedent from 'ts-dedent'

Expand Down Expand Up @@ -82,7 +88,7 @@ function assertCompletion({
textDocument: document,
position,
context: {
triggerKind: 1,
triggerKind: CompletionTriggerKind.Invoked,
},
}

Expand Down Expand Up @@ -131,11 +137,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 +443,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 @@ -1701,14 +1723,6 @@ suite('Completions', function () {
label: '[]',
kind: CompletionItemKind.Value,
}
const staticValueTrue = {
label: 'true',
kind: CompletionItemKind.Value,
}
const staticValueFalse = {
label: 'false',
kind: CompletionItemKind.Value,
}
const enumValueOne = {
label: 'ADMIN',
kind: CompletionItemKind.Value,
Expand All @@ -1718,10 +1732,6 @@ suite('Completions', function () {
kind: CompletionItemKind.Value,
}

const fieldsProperty = {
label: 'fields',
kind: CompletionItemKind.Property,
}
const referencesProperty = {
label: 'references',
kind: CompletionItemKind.Property,
Expand All @@ -1738,18 +1748,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 @@ -2952,4 +2950,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 b1c9c47

Please sign in to comment.