Skip to content

Commit db62499

Browse files
committed
Updated naming scheme to use onError
The variant will use it's own name in `server.ts` - to show what's being given, in this case `showErrorToast`
1 parent 396b731 commit db62499

File tree

5 files changed

+30
-30
lines changed

5 files changed

+30
-30
lines changed

packages/language-server/src/MessageHandler.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ import { createDiagnosticsForIgnore } from './diagnosticsHandler'
7070

7171
export function handleDiagnosticsRequest(
7272
document: TextDocument,
73-
showErrorToast?: (errorMessage: string) => void,
73+
onError?: (errorMessage: string) => void,
7474
): Diagnostic[] {
7575
const text = document.getText(fullDocumentRange(document))
7676
const res = lint(text, (errorMessage: string) => {
77-
if (showErrorToast) {
78-
showErrorToast(errorMessage)
77+
if (onError) {
78+
onError(errorMessage)
7979
}
8080
})
8181

@@ -87,8 +87,8 @@ export function handleDiagnosticsRequest(
8787
diagnostic.text === 'Model declarations have to be indicated with the `model` keyword.',
8888
)
8989
) {
90-
if (showErrorToast) {
91-
showErrorToast(
90+
if (onError) {
91+
onError(
9292
"You might currently be viewing a Prisma 1 datamodel which is based on the GraphQL syntax. The current Prisma Language Server doesn't support this syntax. If you are handling a Prisma 1 datamodel, please change the file extension to `.graphql` so the new Prisma Language Server does not get triggered anymore.",
9393
)
9494
}
@@ -240,13 +240,13 @@ export function handleHoverRequest(document: TextDocument, params: HoverParams):
240240
function prismaFmtCompletions(
241241
params: CompletionParams,
242242
document: TextDocument,
243-
showErrorToast?: (errorMessage: string) => void,
243+
onError?: (errorMessage: string) => void,
244244
): CompletionList | undefined {
245245
const text = document.getText(fullDocumentRange(document))
246246

247247
const completionList = textDocumentCompletion(text, params, (errorMessage: string) => {
248-
if (showErrorToast) {
249-
showErrorToast(errorMessage)
248+
if (onError) {
249+
onError(errorMessage)
250250
}
251251
})
252252

@@ -260,7 +260,7 @@ function prismaFmtCompletions(
260260
function localCompletions(
261261
params: CompletionParams,
262262
document: TextDocument,
263-
showErrorToast?: (errorMessage: string) => void,
263+
onError?: (errorMessage: string) => void,
264264
): CompletionList | undefined {
265265
const context = params.context
266266
const position = params.position
@@ -303,7 +303,7 @@ function localCompletions(
303303
lines,
304304
wordsBeforePosition,
305305
document,
306-
showErrorToast,
306+
onError,
307307
)
308308
case '"':
309309
return getSuggestionForSupportedFields(
@@ -319,7 +319,7 @@ function localCompletions(
319319
if (['model', 'view'].includes(foundBlock.type) && isInsideAttribute(currentLineUntrimmed, position, '()')) {
320320
return getSuggestionsForInsideRoundBrackets(currentLineUntrimmed, lines, document, position, foundBlock)
321321
} else {
322-
return getSuggestionForNativeTypes(foundBlock, lines, wordsBeforePosition, document, showErrorToast)
322+
return getSuggestionForNativeTypes(foundBlock, lines, wordsBeforePosition, document, onError)
323323
}
324324
}
325325
}
@@ -342,7 +342,7 @@ function localCompletions(
342342
lines,
343343
wordsBeforePosition,
344344
document,
345-
showErrorToast,
345+
onError,
346346
)
347347
case 'datasource':
348348
case 'generator':
@@ -376,9 +376,9 @@ function localCompletions(
376376
export function handleCompletionRequest(
377377
params: CompletionParams,
378378
document: TextDocument,
379-
showErrorToast?: (errorMessage: string) => void,
379+
onError?: (errorMessage: string) => void,
380380
): CompletionList | undefined {
381-
return prismaFmtCompletions(params, document, showErrorToast) || localCompletions(params, document, showErrorToast)
381+
return prismaFmtCompletions(params, document, onError) || localCompletions(params, document, onError)
382382
}
383383

384384
export function handleRenameRequest(params: RenameParams, document: TextDocument): WorkspaceEdit | undefined {
@@ -477,13 +477,13 @@ export function handleCompletionResolveRequest(item: CompletionItem): Completion
477477
export function handleCodeActions(
478478
params: CodeActionParams,
479479
document: TextDocument,
480-
showErrorToast?: (errorMessage: string) => void,
480+
onError?: (errorMessage: string) => void,
481481
): CodeAction[] {
482482
if (!params.context.diagnostics.length) {
483483
return []
484484
}
485485

486-
return quickFix(document, params, showErrorToast)
486+
return quickFix(document, params, onError)
487487
}
488488

489489
export function handleDocumentSymbol(params: DocumentSymbolParams, document: TextDocument): DocumentSymbol[] {

packages/language-server/src/codeActionProvider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function addTypeModifiers(hasTypeModifierArray: boolean, hasTypeModifierOptional
8484
export function quickFix(
8585
textDocument: TextDocument,
8686
params: CodeActionParams,
87-
showErrorToast?: (errorMessage: string) => void,
87+
onError?: (errorMessage: string) => void,
8888
): CodeAction[] {
8989
const diagnostics: Diagnostic[] = params.context.diagnostics
9090

@@ -93,8 +93,8 @@ export function quickFix(
9393
}
9494

9595
const codeActionList = codeActions(textDocument.getText(), JSON.stringify(params), (errorMessage: string) => {
96-
if (showErrorToast) {
97-
showErrorToast(errorMessage)
96+
if (onError) {
97+
onError(errorMessage)
9898
}
9999
})
100100

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,11 +516,11 @@ export function handlePreviewFeatures(
516516
export function getNativeTypes(
517517
document: TextDocument,
518518
prismaType: string,
519-
showErrorToast?: (errorMessage: string) => void,
519+
onError?: (errorMessage: string) => void,
520520
): CompletionItem[] {
521521
let nativeTypes: NativeTypeConstructors[] = nativeTypeConstructors(document.getText(), (errorMessage: string) => {
522-
if (showErrorToast) {
523-
showErrorToast(errorMessage)
522+
if (onError) {
523+
onError(errorMessage)
524524
}
525525
})
526526

packages/language-server/src/completion/completions.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ export function getSuggestionForNativeTypes(
117117
lines: string[],
118118
wordsBeforePosition: string[],
119119
document: TextDocument,
120-
showErrorToast?: (errorMessage: string) => void,
120+
onError?: (errorMessage: string) => void,
121121
): CompletionList | undefined {
122-
const activeFeatureFlag = declaredNativeTypes(document, showErrorToast)
122+
const activeFeatureFlag = declaredNativeTypes(document, onError)
123123

124124
if (
125125
// TODO type? native "@db." types?
@@ -137,7 +137,7 @@ export function getSuggestionForNativeTypes(
137137

138138
// line
139139
const prismaType = wordsBeforePosition[1].replace('?', '').replace('[]', '')
140-
const suggestions = getNativeTypes(document, prismaType, showErrorToast)
140+
const suggestions = getNativeTypes(document, prismaType, onError)
141141

142142
return {
143143
items: suggestions,
@@ -163,7 +163,7 @@ export function getSuggestionForFieldAttribute(
163163
lines: string[],
164164
wordsBeforePosition: string[],
165165
document: TextDocument,
166-
showErrorToast?: (errorMessage: string) => void,
166+
onError?: (errorMessage: string) => void,
167167
): CompletionList | undefined {
168168
const fieldType = getFieldType(currentLine)
169169
// If we don't find a field type (e.g. String, Int...), return no suggestion
@@ -177,7 +177,7 @@ export function getSuggestionForFieldAttribute(
177177
if (wordsBeforePosition.length >= 2) {
178178
const datasourceName = getFirstDatasourceName(lines)
179179
const prismaType = wordsBeforePosition[1]
180-
const nativeTypeSuggestions = getNativeTypes(document, prismaType, showErrorToast)
180+
const nativeTypeSuggestions = getNativeTypes(document, prismaType, onError)
181181

182182
if (datasourceName) {
183183
if (!currentLine.includes(`@${datasourceName}`)) {

packages/language-server/src/util.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,10 @@ export function getValuesInsideSquareBrackets(line: string): string[] {
221221
return result
222222
}
223223

224-
export function declaredNativeTypes(document: TextDocument, showErrorToast?: (errorMessage: string) => void): boolean {
224+
export function declaredNativeTypes(document: TextDocument, onError?: (errorMessage: string) => void): boolean {
225225
const nativeTypes: NativeTypeConstructors[] = nativeTypeConstructors(document.getText(), (errorMessage: string) => {
226-
if (showErrorToast) {
227-
showErrorToast(errorMessage)
226+
if (onError) {
227+
onError(errorMessage)
228228
}
229229
})
230230

0 commit comments

Comments
 (0)