Skip to content

Commit

Permalink
Fix (manual) navigation if no editor is opened
Browse files Browse the repository at this point in the history
  • Loading branch information
jtanx committed Oct 7, 2017
1 parent 54609c3 commit 45e6010
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
38 changes: 24 additions & 14 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,20 @@ function findCTagsInDocument(context) {

function findCTags(context, tag) {
const editor = vscode.window.activeTextEditor
let searchPath = editor.document.fileName
if (editor.document.isUntitled || editor.document.uri.scheme !== 'file') {
searchPath = vscode.workspace.rootPath
let searchPath = vscode.workspace.rootPath

if (editor && !editor.document.isUntitled && editor.document.uri.scheme === 'file') {
searchPath = editor.document.fileName
}

if (!searchPath) {
console.log('ctagsx: Could not get a path to search for tags file')
console.log('ctagsx: Document is untitled? ', editor.document.isUntitled)
console.log('ctagsx: Document URI:', editor.document.uri.toString())
if (editor) {
console.log('ctagsx: Document is untitled? ', editor.document.isUntitled)
console.log('ctagsx: Document URI:', editor.document.uri.toString())
} else {
console.log('ctagsx: Active text editor is undefined')
}
console.log('ctagsx: Workspace root: ', vscode.workspace.rootPath)
return vscode.window.showWarningMessage(`ctagsx: No searchable path (no workspace folder open?)`)
}
Expand Down Expand Up @@ -120,6 +125,10 @@ function clearJumpStack(context) {
}

function saveState(context, editor) {
if (!editor) {
// Can happen on manual entry with no editor open
return Promise.resolve()
}
const currentPosition = {
uri: editor.document.uri.toString(),
lineNumber: editor.selection.active.line,
Expand Down Expand Up @@ -188,6 +197,10 @@ function getLineNumber(entry) {
}

function getFileLineNumber(editor) {
if (!editor) {
// Can happen on manual entry with no editor open
return Promise.resolve()
}
let pos = editor.selection.end.translate(0, 1)
let range = editor.document.getWordRangeAtPosition(pos)
if (range) {
Expand Down Expand Up @@ -216,15 +229,12 @@ function openAndReveal(context, editor, document, sel, doSaveState) {
return saveState(context, editor).then(() => openAndReveal(context, editor, document, sel))
}
return vscode.workspace.openTextDocument(document).then(doc => {
const viewColumn = editor ? editor.viewColumn : vscode.ViewColumn.One
const preview = vscode.workspace.getConfiguration('ctagsx').get('openAsPreview')

return vscode.window.showTextDocument(doc, {preview, viewColumn}).then(editor => {
if (sel) {
editor.selection = sel
editor.revealRange(sel, vscode.TextEditorRevealType.InCenter)
}
})
const showOptions = {
viewColumn: vscode.ViewColumn.Active,
preview: vscode.workspace.getConfiguration('ctagsx').get('openAsPreview'),
selection: sel
}
return vscode.window.showTextDocument(doc, showOptions)
})
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"publisher": "jtanx",
"icon": "img/logo.svg",
"engines": {
"vscode": "^1.10.0"
"vscode": "^1.15.0"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 45e6010

Please sign in to comment.