UNPKG

@prisma/language-server

Version:
214 lines • 8.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const vscode_languageserver_1 = require("vscode-languageserver"); const helper_1 = require("../helper"); const _1 = require("."); const MessageHandler_1 = require("../../lib/MessageHandler"); const Schema_1 = require("../../lib/Schema"); const isWindows = process.platform === 'win32'; (0, vitest_1.describe)('blocks', () => { const getFixturePath = (testName) => `./codeActions/blocks/${testName}.prisma`; // Newline differences with windows, courtesy of \r\n. const range = isWindows ? { start: { line: 12, character: 1 }, end: { line: 12, character: 2 }, } : { start: { line: 12, character: 1 }, end: { line: 13, character: 0 }, }; const newLine = isWindows ? '\r\n' : '\n'; (0, vitest_1.test)('create missing block in composite type', () => { const fixturePath = getFixturePath('unknown_type_composite_type'); const expectedPath = (0, helper_1.fixturePathToUri)(fixturePath); const document = (0, helper_1.getTextDocument)(fixturePath); const onError = vitest_1.vi.fn(); const diagnostics = (0, MessageHandler_1.handleDiagnosticsRequest)(Schema_1.PrismaSchema.singleFile(document), onError).get(expectedPath); (0, _1.assertQuickFix)([ { title: "Create new type 'Animal'", kind: vscode_languageserver_1.CodeActionKind.QuickFix, diagnostics, edit: { changes: { [expectedPath]: [ { range, newText: `${newLine}type Animal {${newLine}${newLine}}${newLine}`, }, ], }, }, }, { title: "Create new enum 'Animal'", kind: vscode_languageserver_1.CodeActionKind.QuickFix, diagnostics, edit: { changes: { [expectedPath]: [ { range, newText: `${newLine}enum Animal {${newLine}${newLine}}${newLine}`, }, ], }, }, }, ], document, range, diagnostics); }); (0, vitest_1.test)('create missing block in model - mongodb', () => { const fixturePath = getFixturePath('unknown_type_model_mongodb'); const expectedPath = (0, helper_1.fixturePathToUri)(fixturePath); const document = (0, helper_1.getTextDocument)(fixturePath); const onError = vitest_1.vi.fn(); const diagnostics = (0, MessageHandler_1.handleDiagnosticsRequest)(Schema_1.PrismaSchema.singleFile(document), onError).get(expectedPath); (0, _1.assertQuickFix)([ { title: "Create new model 'Address'", kind: vscode_languageserver_1.CodeActionKind.QuickFix, diagnostics, edit: { changes: { [expectedPath]: [ { range, newText: `${newLine}model Address {${newLine}${newLine}}${newLine}`, }, ], }, }, }, { title: "Create new enum 'Address'", kind: vscode_languageserver_1.CodeActionKind.QuickFix, diagnostics, edit: { changes: { [expectedPath]: [ { range, newText: `${newLine}enum Address {${newLine}${newLine}}${newLine}`, }, ], }, }, }, { title: "Create new type 'Address'", kind: vscode_languageserver_1.CodeActionKind.QuickFix, diagnostics, edit: { changes: { [expectedPath]: [ { range, newText: `${newLine}type Address {${newLine}${newLine}}${newLine}`, }, ], }, }, }, ], document, range, diagnostics); }); (0, vitest_1.test)('create missing block in model - postgres', () => { const fixturePath = getFixturePath('unknown_type_model'); const expectedPath = (0, helper_1.fixturePathToUri)(fixturePath); const document = (0, helper_1.getTextDocument)(fixturePath); const onError = vitest_1.vi.fn(); const diagnostics = (0, MessageHandler_1.handleDiagnosticsRequest)(Schema_1.PrismaSchema.singleFile(document), onError).get(expectedPath); (0, _1.assertQuickFix)([ { title: "Create new model 'Animal'", kind: vscode_languageserver_1.CodeActionKind.QuickFix, diagnostics, edit: { changes: { [expectedPath]: [ { range, newText: `${newLine}model Animal {${newLine}${newLine}}${newLine}`, }, ], }, }, }, { title: "Create new enum 'Animal'", kind: vscode_languageserver_1.CodeActionKind.QuickFix, diagnostics, edit: { changes: { [expectedPath]: [ { range, newText: `${newLine}enum Animal {${newLine}${newLine}}${newLine}`, }, ], }, }, }, ], document, range, diagnostics); }); (0, vitest_1.test)('spelling', () => { const fixturePath = getFixturePath('spelling'); const expectedPath = (0, helper_1.fixturePathToUri)(fixturePath); const document = (0, helper_1.getTextDocument)(fixturePath); const onError = vitest_1.vi.fn(); const diagnostics = (0, MessageHandler_1.handleDiagnosticsRequest)(Schema_1.PrismaSchema.singleFile(document), onError).get(expectedPath); const rangeSpelling = { start: { line: 11, character: 12 }, end: { line: 11, character: 18 }, }; (0, _1.assertQuickFix)([ { title: "Create new model 'Animol'", kind: vscode_languageserver_1.CodeActionKind.QuickFix, diagnostics, edit: { changes: { [expectedPath]: [ { range: range, newText: `${newLine}model Animol {${newLine}${newLine}}${newLine}`, }, ], }, }, }, { title: "Create new enum 'Animol'", kind: vscode_languageserver_1.CodeActionKind.QuickFix, diagnostics, edit: { changes: { [expectedPath]: [ { range: range, newText: `${newLine}enum Animol {${newLine}${newLine}}${newLine}`, }, ], }, }, }, { title: "Change spelling to 'Animal'", kind: vscode_languageserver_1.CodeActionKind.QuickFix, diagnostics, edit: { changes: { [expectedPath]: [ { range: rangeSpelling, newText: 'Animal', }, ], }, }, }, ], document, range, diagnostics); }); }); //# sourceMappingURL=block.test.js.map