UNPKG

plaxtony

Version:

Static code analysis of SC2 Galaxy Script

92 lines 3.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.dump = exports.mapStoreFilesByBasename = exports.mockupStoreFromS2Workspace = exports.mockupStoreFromDirectory = exports.mockupStore = exports.mockupStoreDocument = exports.mockupSourceFile = exports.mockupTextDocument = exports.fixtureFilePath = void 0; const parser_1 = require("../src/compiler/parser"); const store_1 = require("../src/service/store"); const path = require("path"); const util = require("util"); const fixturesPath = 'tests/fixtures'; function fixtureFilePath(...filepath) { return path.join(fixturesPath, ...filepath); } exports.fixtureFilePath = fixtureFilePath; function mockupTextDocument(...filepath) { return store_1.createTextDocumentFromFs(fixtureFilePath(...filepath)); } exports.mockupTextDocument = mockupTextDocument; function mockupSourceFile(...filepath) { const parser = new parser_1.Parser(); const completeFilePath = fixtureFilePath(...filepath); const document = store_1.createTextDocumentFromFs(completeFilePath); return parser.parseFile(path.basename(completeFilePath), document.getText()); } exports.mockupSourceFile = mockupSourceFile; function mockupStoreDocument(...filepath) { const store = new store_1.Store(); const document = store_1.createTextDocumentFromFs(fixtureFilePath(...filepath)); store.updateDocument(document); return [store, store.documents.get(document.uri)]; } exports.mockupStoreDocument = mockupStoreDocument; function mockupStore(...documents) { const store = new store_1.Store(); for (const doc of documents) { store.updateDocument(doc); } return store; } exports.mockupStore = mockupStore; async function mockupStoreFromDirectory(directory) { const store = new store_1.Store(); store.rootPath = directory; for await (const doc of store_1.openSourceFilesInLocation(directory)) { store.updateDocument(doc); } return store; } exports.mockupStoreFromDirectory = mockupStoreFromDirectory; async function mockupStoreFromS2Workspace(directory, modSources) { const store = new store_1.Store(); const ws = new store_1.S2WorkspaceWatcher(directory, modSources); const workspaces = []; ws.onDidOpen((ev) => { store.updateDocument(ev.document); }); ws.onDidOpenS2Archive((ev) => { workspaces.push(ev.workspace); }); await ws.watch(); for (const ws of workspaces) { await store.updateS2Workspace(ws); await store.rebuildS2Metadata(); } return store; } exports.mockupStoreFromS2Workspace = mockupStoreFromS2Workspace; function mapStoreFilesByBasename(store) { const m = new Map(); for (const [fullname, sourceFile] of store.documents.entries()) { m.set(path.basename(fullname), sourceFile); } return m; } exports.mapStoreFilesByBasename = mapStoreFilesByBasename; function printDiagnostics(diagnostics) { const r = []; for (const diag of diagnostics) { console.log(diag); r.push(diag.toString()); } return r.join('\n'); } function dump(d) { return util.inspect(d, { colors: true, depth: 3, compact: true, maxArrayLength: 500, breakLength: 140, }); } exports.dump = dump; //# sourceMappingURL=helpers.js.map