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

Commit

Permalink
Added feature find references (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
haiyangToAI authored Jan 19, 2023
1 parent 5d4d8cb commit 52adbd8
Show file tree
Hide file tree
Showing 9 changed files with 309 additions and 72 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ hover.

![image](https://raw.githubusercontent.com/useblocks/sphinx-needs-vscode/main/docs/_images/features_goto.gif)

**Find References:**

![image](https://raw.githubusercontent.com/useblocks/sphinx-needs-vscode/main/docs/_images/features_find_references.gif)

**ID Selection:**

![image](https://raw.githubusercontent.com/useblocks/sphinx-needs-vscode/main/docs/_images/features_id_selection.gif)
Expand Down
83 changes: 71 additions & 12 deletions client/src/test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ suite('Sphinx-Needs Extension Tests for rst file', function () {

const testCases: [string, vscode.Position, vscode.CompletionList][] = [
['trigger ..', new vscode.Position(10, 2), expectedSnippets],
['trigger :', new vscode.Position(30, 1), expectedNeedRoleOrOption],
['trigger > at lev1', new vscode.Position(34, 9), expectedNeedPathLev1],
['trigger > at lev2', new vscode.Position(36, 13), expectedNeedPathLev2],
['trigger > at lev3', new vscode.Position(38, 23), expectedNeedPathLev3],
['trigger /', new vscode.Position(40, 25), expectedPathFolderInsider]
['trigger :', new vscode.Position(33, 1), expectedNeedRoleOrOption],
['trigger > at lev1', new vscode.Position(37, 9), expectedNeedPathLev1],
['trigger > at lev2', new vscode.Position(39, 13), expectedNeedPathLev2],
['trigger > at lev3', new vscode.Position(41, 23), expectedNeedPathLev3],
['trigger /', new vscode.Position(43, 25), expectedPathFolderInsider]
];

const promises = testCases.map(async ([name, position, expectedItems]) => {
Expand Down Expand Up @@ -185,25 +185,25 @@ suite('Sphinx-Needs Extension Tests for rst file', function () {
await activate(docUri);

const testCases: [string, vscode.Position, string, vscode.Position][] = [
['goto same file', new vscode.Position(19, 12), docUri.path, new vscode.Position(18, 0)],
['goto same file', new vscode.Position(20, 12), docUri.path, new vscode.Position(19, 0)],
[
'goto different file',
new vscode.Position(32, 1),
new vscode.Position(35, 1),
path.resolve(__dirname, '../../testData/mySubFolder', 'sub.rst'),
new vscode.Position(3, 0)
],
['goto multiple ID same line', new vscode.Position(32, 10), docUri.path, new vscode.Position(18, 0)],
['goto multiple ID same line', new vscode.Position(35, 10), docUri.path, new vscode.Position(19, 0)],
[
'goto option with multiple ID first',
new vscode.Position(13, 15),
docUri.path,
new vscode.Position(18, 0)
new vscode.Position(19, 0)
],
[
'goto option with multiple ID last',
new vscode.Position(13, 22),
new vscode.Position(13, 28),
path.resolve(__dirname, '../../testData/mySubFolder', 'sub.rst'),
new vscode.Position(9, 0)
new vscode.Position(3, 0)
],
['negative goto', new vscode.Position(6, 3), '', new vscode.Position(0, 0)]
];
Expand All @@ -229,9 +229,68 @@ suite('Sphinx-Needs Extension Tests for rst file', function () {
});
return Promise.all(promises);
});

// Test Find References
test('Test Find References', async () => {
// Activate extension
await activate(docUri);

const testCases: [string, vscode.Position, vscode.Location[]][] = [
[
'find references multiple',
new vscode.Position(22, 14),
[
new vscode.Location(
docUri,
new vscode.Range(new vscode.Position(13, 19), new vscode.Position(13, 24))
),
new vscode.Location(
docUri,
new vscode.Range(new vscode.Position(22, 11), new vscode.Position(22, 16))
)
]
],
[
'find references single',
new vscode.Position(20, 10),
[
new vscode.Location(
docUri,
new vscode.Range(new vscode.Position(13, 11), new vscode.Position(13, 17))
)
]
]
];

const promises = testCases.map(async ([name, position, expectedLocations]) => {
const allReferences = (await vscode.commands.executeCommand(
'vscode.executeReferenceProvider',
docUri,
position
)) as vscode.Location[];

if (name === 'find references multiple') {
assert.ok(allReferences.length === 2, `Find References over ${name} failed.`);
}

if (name === 'find references single') {
assert.ok(allReferences.length === 1, `Find References over ${name} failed.`);
}

expectedLocations.forEach((expLoc, i) => {
const actualRef = allReferences[i];
assert.equal(actualRef.uri.path, expLoc.uri.path);
assert.equal(actualRef.range.start.line, expLoc.range.start.line);
assert.equal(actualRef.range.start.character, expLoc.range.start.character);
assert.equal(actualRef.range.end.line, expLoc.range.end.line);
assert.equal(actualRef.range.end.character, expLoc.range.end.character);
});
});
return Promise.all(promises);
});
});

suite('Sphinx-Needs Extension Tests for plaintext file', function() {
suite('Sphinx-Needs Extension Tests for plaintext file', function () {
this.timeout(30000);

// Test Document
Expand Down
11 changes: 11 additions & 0 deletions client/testData/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@
{"directive": "need", "title": "Need", "prefix": "N_", "color": "#9856a5", "style": "node"},
]

needs_extra_links = [
{
"option": "tests",
"incoming": "is tested by",
"outgoing": "tests",
"copy": True,
"style": "#00AA00",
"style_part": "dotted,#00AA00",
}
]

needs_build_json = True

# Add any paths that contain templates here, relative to this directory.
Expand Down
7 changes: 5 additions & 2 deletions client/testData/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@ Needs
.. req:: First requirement
:id: REQ_1
:status: open
:links: SPEC_1, REQ_3
:links: SPEC_1, REQ_3, REQ_2
:tests: REQ_2

Requirement content


.. spec:: First specification
:id: SPEC_1
:status: open
:links: REQ_3
:tests: REQ_2

Specification content

.. spec:: Dummy Title
:id: 3f3b1468
:id: SPEC_3
:status: open

Content.
Expand Down
20 changes: 16 additions & 4 deletions client/testData/needs_small.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,43 @@
"type": "req",
"description": "Description for REQ_1.",
"docname": "index",
"doctype": ".rst"
"doctype": ".rst",
"links": ["SPEC_1", "REQ_3", "REQ_2"],
"tests": ["REQ_2"],
"tests_back": []
},
"SPEC_1": {
"id": "SPEC_1",
"title": "example spec",
"type": "spec",
"description": "Description for SPEC_1.",
"docname": "index",
"doctype": ".rst"
"doctype": ".rst",
"links": ["REQ_3"],
"tests": ["REQ_2"],
"tests_back": []
},
"REQ_2": {
"id": "REQ_2",
"title": "example second req",
"type": "req",
"description": "Description for REQ_2.",
"docname": "mySubFolder/sub",
"doctype": ".rst"
"doctype": ".rst",
"links": [],
"tests": [],
"tests_back": ["REQ_1", "SPEC_1"]
},
"REQ_3": {
"id": "REQ_3",
"title": "example third req",
"type": "req",
"description": "Description for REQ_3.",
"docname": "mySubFolder/sub",
"doctype": ".rst"
"doctype": ".rst",
"links": [],
"tests": [],
"tests_back": []
}
}
}
Expand Down
Binary file added docs/_images/features_find_references.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Under development
* Updated homepage for extension
* Adapted extension activationEvents to workspace contains ``conf.py``.
* Added setting :ref:`activateFiles` to config supported files that language features will be activated when file opened.
* Added feature :ref:`find_references`.

0.1.1
-----
Expand Down
10 changes: 10 additions & 0 deletions docs/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ The extension enables you to navigate your documentation project using the *need
.. image:: /_images/features_goto.gif
:align: center

.. _find_references:

Find References
---------------

Find all other *need* objects that link to current *need ID*.

.. image:: /_images/features_find_references.gif
:align: center

.. _id_select:

Need ID Selection
Expand Down
Loading

0 comments on commit 52adbd8

Please sign in to comment.