@prisma/language-server
Version:
Prisma Language Server
77 lines • 3.52 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.findCursorPosition = exports.CURSOR_CHARACTER = void 0;
exports.getTextDocument = getTextDocument;
exports.fixturePathToUri = fixturePathToUri;
const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
const vscode_uri_1 = require("vscode-uri");
const fs = __importStar(require("fs"));
const path_1 = __importDefault(require("path"));
exports.CURSOR_CHARACTER = '|';
const fixturesDir = path_1.default.resolve(__dirname, '__fixtures__/single-file');
function getTextDocument(testFilePath) {
const absPath = path_1.default.join(fixturesDir, testFilePath);
const content = fs.readFileSync(absPath, 'utf8');
return vscode_languageserver_textdocument_1.TextDocument.create(fixturePathToUri(absPath), 'prisma', 1, content);
}
function fixturePathToUri(fixturePath, rootDir = fixturesDir) {
const absPath = path_1.default.isAbsolute(fixturePath) ? fixturePath : path_1.default.join(rootDir, fixturePath);
// that would normalize testFilePath and resolve all of
// the . and ..
const relPath = path_1.default.relative(rootDir, absPath);
// this will normalize slashes on win/linux
return vscode_uri_1.URI.file(`/${relPath}`).toString();
}
const findCursorPosition = (input) => {
const lines = input.split('\n');
let foundCursorCharacter = -1;
const foundLinePosition = lines.findIndex((line) => {
const cursorPosition = line.indexOf(exports.CURSOR_CHARACTER);
if (cursorPosition !== -1) {
foundCursorCharacter = cursorPosition;
return true;
}
});
if (foundLinePosition >= 0 && foundCursorCharacter >= 0) {
return { line: foundLinePosition, character: foundCursorCharacter };
}
throw new Error('Each test must include the `|` pipe character to signal where the cursor should be when executing the test.');
};
exports.findCursorPosition = findCursorPosition;
//# sourceMappingURL=helper.js.map