Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

LSP Find References Feature #14693

Merged
merged 14 commits into from
Apr 15, 2019
3 changes: 3 additions & 0 deletions src/base-config/keyboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@
"cmd.findInFiles": [
"Ctrl-Shift-F"
],
"cmd.findAllReferences": [
"Shift-F12"
],
"cmd.replaceInFiles": [
{
"key": "Ctrl-Shift-H"
Expand Down
1 change: 1 addition & 0 deletions src/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ define(function (require, exports, module) {
//load language features
require("features/ParameterHintsManager");
require("features/JumpToDefManager");
require("features/FindReferencesManager");

// Load modules that self-register and just need to get included in the main project
require("command/DefaultMenus");
Expand Down
1 change: 1 addition & 0 deletions src/command/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ define(function (require, exports, module) {
exports.CMD_REPLACE = "cmd.replace"; // FindReplace.js _replace()
exports.CMD_REPLACE_IN_FILES = "cmd.replaceInFiles"; // FindInFilesUI.js _showReplaceBar()
exports.CMD_REPLACE_IN_SUBTREE = "cmd.replaceInSubtree"; // FindInFilesUI.js _showReplaceBarForSubtree()
exports.CMD_FIND_ALL_REFERENCES = "cmd.findAllReferences"; // findReferencesManager.js _openReferencesPanel()

// VIEW
exports.CMD_THEMES_OPEN_SETTINGS = "view.themesOpenSetting"; // MenuCommands.js Settings.open()
Expand Down
2 changes: 2 additions & 0 deletions src/command/DefaultMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ define(function (require, exports, module) {
menu.addMenuItem(Commands.CMD_SKIP_CURRENT_MATCH);
menu.addMenuDivider();
menu.addMenuItem(Commands.CMD_FIND_IN_FILES);
menu.addMenuItem(Commands.CMD_FIND_ALL_REFERENCES);
menu.addMenuDivider();
menu.addMenuItem(Commands.CMD_REPLACE);
menu.addMenuItem(Commands.CMD_REPLACE_IN_FILES);
Expand Down Expand Up @@ -283,6 +284,7 @@ define(function (require, exports, module) {
// editor_cmenu.addMenuItem(Commands.NAVIGATE_JUMPTO_DEFINITION);
editor_cmenu.addMenuItem(Commands.TOGGLE_QUICK_EDIT);
editor_cmenu.addMenuItem(Commands.TOGGLE_QUICK_DOCS);
editor_cmenu.addMenuItem(Commands.CMD_FIND_ALL_REFERENCES);
editor_cmenu.addMenuDivider();
editor_cmenu.addMenuItem(Commands.EDIT_CUT);
editor_cmenu.addMenuItem(Commands.EDIT_COPY);
Expand Down
6 changes: 5 additions & 1 deletion src/extensions/default/PhpTooling/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ define(function (require, exports, module) {
QuickOpen = brackets.getModule("search/QuickOpen"),
ParameterHintManager = brackets.getModule("features/ParameterHintsManager"),
JumpToDefManager = brackets.getModule("features/JumpToDefManager"),
FindReferencesManager = brackets.getModule("features/FindReferencesManager"),
CodeInspection = brackets.getModule("language/CodeInspection"),
DefaultProviders = brackets.getModule("languageTools/DefaultProviders"),
CodeHintsProvider = require("CodeHintsProvider").CodeHintsProvider,
Expand Down Expand Up @@ -65,7 +66,8 @@ define(function (require, exports, module) {
lProvider,
jdProvider,
dSymProvider,
pSymProvider;
pSymProvider,
refProvider;
shubhsnov marked this conversation as resolved.
Show resolved Hide resolved

PreferencesManager.definePreference("php", "object", phpConfig, {
description: Strings.DESCRIPTION_PHP_TOOLING_CONFIGURATION
Expand Down Expand Up @@ -108,10 +110,12 @@ define(function (require, exports, module) {
jdProvider = new DefaultProviders.JumpToDefProvider(_client);
dSymProvider = new SymbolProviders.DocumentSymbolsProvider(_client);
pSymProvider = new SymbolProviders.ProjectSymbolsProvider(_client);
refProvider = new DefaultProviders.ReferencesProvider(_client);

JumpToDefManager.registerJumpToDefProvider(jdProvider, ["php"], 0);
CodeHintManager.registerHintProvider(chProvider, ["php"], 0);
ParameterHintManager.registerHintProvider(phProvider, ["php"], 0);
FindReferencesManager.registerFindReferencesProvider(refProvider, ["php"], 0);
CodeInspection.register(["php"], {
name: "",
scanFileAsync: lProvider.getInspectionResultsAsync.bind(lProvider)
Expand Down
17 changes: 17 additions & 0 deletions src/extensions/default/PhpTooling/unittest-files/test/test2.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,22 @@ function watchparameterhint() {
$A11()
fopen("",)
watchparameterhint()


function watchReferences() {
echo "Hello World!";
}

watchReferences();

watchReferences();


function ReferencesInMultipleFile() {
echo "Hello World!";
}

ReferencesInMultipleFile();

ReferencesInMultipleFile();
?>
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ class testA
protected $B = [
'A1', 'A2'
];
}
}

ReferencesInMultipleFile();
140 changes: 140 additions & 0 deletions src/extensions/default/PhpTooling/unittests.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,40 @@ define(function (require, exports, module) {

}

function expectReferences(referencesExpected) {
var refPromise,
results = null,
complete = false;
runs(function () {
refPromise = (new DefaultProviders.ReferencesProvider(phpToolingExtension.getClient())).getReferences();
refPromise.done(function (resp) {
complete = true;
results = resp;
}).fail(function(){
complete = true;
});
});

waitsFor(function () {
return complete;
}, "Expected Reference Promise did not resolve", 3000);

if(referencesExpected === null) {
expect(results).toBeNull();
return;
}

runs(function() {
expect(results.numFiles).toBe(referencesExpected.numFiles);
expect(results.numMatches).toBe(referencesExpected.numMatches);
expect(results.allResultsAvailable).toBe(referencesExpected.allResultsAvailable);
expect(results.results).not.toBeNull();
for(var key in results.keys) {
expect(results.results.key).toBe(referencesExpected.results.key);
}
});
}

/**
* Check the presence of Error Prompt on Brackets Window
*/
Expand Down Expand Up @@ -533,6 +567,112 @@ define(function (require, exports, module) {
});
});

it("should not show any references", function () {
var start = { line: 6, ch: 4 };

runs(function () {
testEditor = EditorManager.getActiveEditor();
testEditor.setCursorPos(start);
expectReferences(null);
});
});

it("should show reference present in single file", function () {
var start = { line: 22, ch: 18 },
results = {};

runs(function () {
testEditor = EditorManager.getActiveEditor();
testEditor.setCursorPos(start);
results[testFolder + "test/test2.php"] = {matches: [
{
start: {line: 27, ch: 0},
end: {line: 27, ch: 18},
line: "watchparameterhint()"
}
]
};
expectReferences({
numFiles: 1,
numMatches: 1,
allResultsAvailable: true,
queryInfo: "watchparameterhint",
keys: [testFolder + "test/test2.php"],
results: results
});
});
});

it("should show references present in single file", function () {
var start = { line: 34, ch: 8 },
results = {};

runs(function () {
testEditor = EditorManager.getActiveEditor();
testEditor.setCursorPos(start);
results[testFolder + "test/test2.php"] = {matches: [
{
start: {line: 34, ch: 0},
end: {line: 34, ch: 17},
line: "watchReferences();"
},
{
start: {line: 36, ch: 0},
end: {line: 36, ch: 17},
line: "watchReferences();"
}
]
};
expectReferences({
numFiles: 1,
numMatches: 2,
allResultsAvailable: true,
queryInfo: "watchparameterhint",
keys: [testFolder + "test/test2.php"],
results: results
});
});
});

it("should show references present in multiple files", function () {
var start = { line: 39, ch: 21 },
results = {};

runs(function () {
testEditor = EditorManager.getActiveEditor();
testEditor.setCursorPos(start);
results[testFolder + "test/test2.php"] = {matches: [
{
start: {line: 34, ch: 0},
end: {line: 34, ch: 26},
line: "watchReferences();"
},
{
start: {line: 36, ch: 0},
end: {line: 36, ch: 26},
line: "watchReferences();"
}
]
};
results[testFolder + "test/test3.php"] = {matches: [
{
start: {line: 11, ch: 0},
end: {line: 11, ch: 26},
line: "watchReferences();"
}
]
};
expectReferences({
numFiles: 2,
numMatches: 3,
allResultsAvailable: true,
queryInfo: "watchparameterhint",
keys: [testFolder + "test/test2.php", testFolder + "test/test3.php"],
results: results
});
});
});

it("should jump to earlier defined variable", function () {
var start = { line: 4, ch: 2 };

Expand Down
Loading