FileCache.prototype.getLineText = function (fileName, line) { var source = this.ls.getSourceFile(fileName); var lineStart = ts.getPositionOfLineAndCharacter(source, line - 1, 0); var lineEnd = ts.getPositionOfLineAndCharacter(source, line, 0) - 1; var lineText = source.text.substring(lineStart, lineEnd); return lineText; };
function spanAt(sourceFile, line, column) { if (line != null && column != null) { var position_1 = ts.getPositionOfLineAndCharacter(sourceFile, line, column); var findChild = function findChild(node) { if (node.kind > ts.SyntaxKind.LastToken && node.pos <= position_1 && node.end > position_1) { var betterNode = ts.forEachChild(node, findChild); return betterNode || node; } }; var node = ts.forEachChild(sourceFile, findChild); if (node) { return { start: node.getStart(), end: node.getEnd() }; } } }
Documenter.prototype.documentThis = function (editor, edit, commandName) { var selection = editor.selection; var caret = selection.start; var sourceFile = this._getSourceFile(editor.document); var position = ts.getPositionOfLineAndCharacter(sourceFile, caret.line, caret.character); var node = utils.findChildForPosition(sourceFile, position); var documentNode = utils.nodeIsOfKind(node) ? node : utils.findFirstParent(node); if (!documentNode) { this._showFailureMessage(commandName, "at the current caret position"); return; } var sb = new utils.StringBuilder(); var docLocation = this._documentNode(sb, documentNode, editor, sourceFile); if (docLocation) { this._insertDocumentation(sb, docLocation, editor, edit, sourceFile); } else { this._showFailureMessage(commandName, "at the current caret position"); } };
Documenter.prototype.traceNode = function (editor, edit) { var selection = editor.selection; var caret = selection.start; var sourceFile = this._getSourceFile(editor.document); var position = ts.getPositionOfLineAndCharacter(sourceFile, caret.line, caret.character); var node = utils.findChildForPosition(sourceFile, position); var nodes = []; var parent = node; while (parent) { nodes.push(this._printNodeInfo(parent, sourceFile)); parent = parent.parent; } var sb = new utils.StringBuilder(); nodes.reverse().forEach(function (n) { sb.appendLine(n); }); if (!this._outputChannel) { this._outputChannel = vs.window.createOutputChannel("TypeScript Syntax Node Trace"); } this._outputChannel.show(); this._outputChannel.appendLine(sb.toString()); };
return hasDoubleNewLine(sourceFile, elementStart) || comments.some(function (comment) { var commentLine = ts.getLineAndCharacterOfPosition(sourceFile, comment.pos).line; var commentLineStartPosition = ts.getPositionOfLineAndCharacter(sourceFile, commentLine, 0); return hasDoubleNewLine(sourceFile, commentLineStartPosition - 4); });
function documentThis() { var textEditor = vscode.window.activeTextEditor; var document = textEditor.document; if (!document.fileName) { return; } var selection = textEditor.selection; // Null check the selection var carat = selection.start; var fileName = utils.fixWinPath(document.fileName); var config = resolveAndLoadConfig(fileName); var files = {}; var rootFileNames = config ? config.fileNames : [fileName]; rootFileNames = rootFileNames.map(function (f) { return utils.fixWinPath(f); }); // initialize the list of files rootFileNames.forEach(function (fileName) { files[fileName] = { version: 0 }; }); // Create the language service host to allow the LS to communicate with the host var servicesHost = { getScriptFileNames: function () { return rootFileNames; }, getScriptVersion: function (fileName) { return files[fileName] && files[fileName].version.toString(); }, getScriptSnapshot: function (fileName) { if (!fs.existsSync(fileName)) { return undefined; } return ts.ScriptSnapshot.fromString(fs.readFileSync(fileName).toString()); }, getCurrentDirectory: function () { return vscode.workspace.rootPath ? utils.fixWinPath(path.resolve(vscode.workspace.rootPath)) : process.cwd(); }, getCompilationSettings: function () { return config ? config.options : {}; }, getDefaultLibFileName: function (options) { return ts.getDefaultLibFilePath(options); }, }; // Create the language service files var services = ts.createLanguageService(servicesHost, ts.createDocumentRegistry()); //const program = services.getProgram(); // const sourceFile = services.getSourceFile(fileName); // //services.getQuickInfoAtPosition // //const definitions = services.getDefinitionAtPosition(document.fileName, carat.character); // const f = services.getTypeDefinitionAtPosition(fileName, carat.character); //services.getDefinitionAtPosition(utils.fixWinPath(document.fileName), carat.character); var program = services.getProgram(); var typeChecker = program.getTypeChecker(); var sourceFile = services.getSourceFile(fileName); var position = ts.getPositionOfLineAndCharacter(sourceFile, carat.line, carat.character); var node = utils.findChildForPosition(sourceFile, position); //const signatureHelpItems = services.getSignatureHelpItems(fileName, position); //const symbol = typeChecker.getSymbolAtLocation() ///const output = services.getEmitOutput(fileName); //console.log("whee"); //let t = sourceFile.getFirstToken(sourceFile); //let qi = services.getQuickInfoAtPosition(fileName, ) //tc.getSymbolAtLocation() // let allDiagnostics = services.getCompilerOptionsDiagnostics() // .concat(services.getSyntacticDiagnostics(fileName)) // .concat(services.getSemanticDiagnostics(fileName)); // // allDiagnostics.forEach(diagnostic => { // let message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"); // if (diagnostic.file) { // let { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start); // console.log(` Error ${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`); // } // else { // console.log(` Error: ${message}`); // } // }); }
FileCache.prototype.lineColToPosition = function (fileName, line, col) { var script = this.getScriptInfo(fileName); return ts.getPositionOfLineAndCharacter(this.ls.getSourceFile(fileName), line - 1, col - 1); };