Skip to content

Commit

Permalink
This is a companion to this engines PR:
Browse files Browse the repository at this point in the history
  • Loading branch information
Druue committed Jun 17, 2024
1 parent aeecb52 commit e181364
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/language-server/src/lib/MessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
import { prismaSchemaWasmCompletions, localCompletions } from './completions'
import { PrismaSchema, SchemaDocument } from './Schema'
import { DiagnosticMap } from './DiagnosticMap'
import hover from './prisma-schema-wasm/hover'

export function handleDiagnosticsRequest(
schema: PrismaSchema,
Expand Down Expand Up @@ -187,7 +188,14 @@ export function handleHoverRequest(
schema: PrismaSchema,
initiatingDocument: TextDocument,
params: HoverParams,
onError?: (errorMessage: string) => void,
): Hover | undefined {
const hover_res = hover(schema, initiatingDocument, params, onError)

if (hover_res) {
return hover_res
}

const position = params.position

const word = getWordAtPosition(initiatingDocument, position)
Expand Down
31 changes: 31 additions & 0 deletions packages/language-server/src/lib/prisma-schema-wasm/hover.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Hover, HoverParams } from 'vscode-languageserver'
import { prismaSchemaWasm } from '.'
import { handleFormatPanic, handleWasmError } from './internals'
import { PrismaSchema } from '../Schema'
import { TextDocument } from 'vscode-languageserver-textdocument'

export default function hover(
schema: PrismaSchema,
initiatingDocument: TextDocument,
params: HoverParams,
onError?: (errorMessage: string) => void,
): Hover | undefined {
try {
if (process.env.FORCE_PANIC_PRISMA_SCHEMA) {
handleFormatPanic(() => {
console.debug('Triggering a Rust panic...')
prismaSchemaWasm.debug_panic()
})
}

const result = prismaSchemaWasm.hover(JSON.stringify(schema), JSON.stringify(params))

return JSON.parse(result) as Hover
} catch (e) {
const err = e as Error

handleWasmError(err, 'hover', onError)

return undefined
}
}
2 changes: 1 addition & 1 deletion packages/language-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export function startServer(options?: LSOptions): void {
const doc = getDocument(params.textDocument.uri)
if (doc) {
const schema = await PrismaSchema.load(doc, documents)
return MessageHandler.handleHoverRequest(schema, doc, params)
return MessageHandler.handleHoverRequest(schema, doc, params, showErrorToast)
}
})

Expand Down

0 comments on commit e181364

Please sign in to comment.