Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 34 additions & 30 deletions src/languageTools/DefaultProviders.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
Strings = require("strings"),
StringUtils = require("utils/StringUtils"),
Metrics = require("utils/Metrics"),
ModalBar = require("widgets/ModalBar").ModalBar,
marked = require("thirdparty/marked.min"),
matcher = new StringMatch.StringMatcher({
preferPrefixMatches: true
Expand Down Expand Up @@ -850,41 +851,30 @@
metricLabel = this.client._metricLabel,
$deferredHints = $.Deferred();

function jumpToLocation(location) {
var startCurPos = { line: location.range.start.line, ch: location.range.start.character };
if (location.uri !== docPathUri) {
CommandManager.execute(Commands.FILE_OPEN, { fullPath: PathConverters.uriToPath(location.uri) })
.done(function () { setJumpPosition(startCurPos); $deferredHints.resolve(); })
.fail(function () { $deferredHints.reject(); });
} else { //definition is in current document
setJumpPosition(startCurPos);
$deferredHints.resolve();
}
}

this.client.gotoDefinition({
filePath: docPath,
cursorPos: pos
}).done(function (msgObj) {
//For Older servers
if (Array.isArray(msgObj)) {
msgObj = msgObj[msgObj.length - 1];
if (Array.isArray(msgObj) && msgObj.length > 1) {
showJumpTargetPicker(msgObj, jumpToLocation, $deferredHints.reject);
return;
}

if (msgObj && msgObj.range) {
var docUri = msgObj.uri,
startCurPos = {};
startCurPos.line = msgObj.range.start.line;
startCurPos.ch = msgObj.range.start.character;

if (docUri !== docPathUri) {
let documentPath = PathConverters.uriToPath(docUri);
CommandManager.execute(Commands.FILE_OPEN, {
fullPath: documentPath
})
.done(function () {
setJumpPosition(startCurPos);
$deferredHints.resolve();
})
.fail(function () {
$deferredHints.reject();
});
} else { //definition is in current document
setJumpPosition(startCurPos);
$deferredHints.resolve();
}
} else {
// No definition at this position (servers answer null/[] - e.g. tsserver while it
// is still loading the project). MUST settle: an unresolved deferred here leaves
// the NAVIGATE_JUMPTO_DEFINITION command promise pending forever.
var location = Array.isArray(msgObj) ? msgObj[0] : msgObj;
if (location && location.range) {

Check warning on line 875 in src/languageTools/DefaultProviders.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer using an optional chain expression instead, as it's more concise and easier to read.

See more on https://sonarcloud.io/project/issues?id=phcode-dev_phoenix&issues=AaAJo72w3ej0ChNoYsNC&open=AaAJo72w3ej0ChNoYsNC&pullRequest=3098
jumpToLocation(location);
} else { // no definition - settle promise
$deferredHints.reject();
}
}).fail(function (err) {
Expand All @@ -898,6 +888,20 @@
return $deferredHints;
};

function showJumpTargetPicker(locations, onPick, onCancel) {
var $bar = $('<div style="padding:4px;"></div>').text(Strings.JUMP_TO_DEFINITION_MULTIPLE_PROMPT);
locations.forEach(function (loc, i) {
$("<button type='button' class='btn'>")
.text(PathConverters.uriToPath(loc.uri).split(/[\\/]/).pop() + ":" + (loc.range.start.line + 1) + ":" + (loc.range.start.character + 1))
.click(function () {
modalBar.close(false, false, ModalBar.CLOSE_API); onPick(loc);
}).appendTo($bar);
});

var modalBar = new ModalBar($bar, true, false);
modalBar.on("close", function (_evt, reason) { if (reason !== ModalBar.CLOSE_API) { onCancel(); } });
}

function LintingProvider() {
this._results = new Map();
this._promiseMap = new Map();
Expand Down
2 changes: 2 additions & 0 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,8 @@ define({
"COLOR_EDITOR_USED_COLOR_TIP_PLURAL": "{0} (Used {1} times)",
"EDIT": "Edit",

"JUMP_TO_DEFINITION_MULTIPLE_PROMPT": "Multiple definitions. Select one:",

// extensions/default/JavaScriptCodeHints
"CMD_JUMPTO_DEFINITION": "Go to Definition",
"CMD_SHOW_PARAMETER_HINT": "Show Parameter Hint",
Expand Down