Repository navigation
feat(document links): preserve PCH document links and add #embed support #413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
13527b7
feat(feature): preserve PCH document links and add #embed/#has_embed …
16bit-ykiko 4926b4a
test(document links): add __has_embed integration tests
16bit-ykiko 4d8c335
fix: re-lookup session after co_await to avoid invalidated iterator
16bit-ykiko 8af2704
refactor: reuse find_filename_range for has_include scanning
16bit-ykiko 02e4f74
style: remove verbose comments from integration tests
16bit-ykiko b691ed1
refactor: extract add_link_by_location to deduplicate has_include/emb…
16bit-ykiko d48236d
refactor: unify include handling with add_link_by_location
16bit-ykiko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 0123456789 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #pragma once | ||
|
|
||
| int a = 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #pragma once | ||
|
|
||
| int b = 2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #pragma once | ||
|
|
||
| int c = 3; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #include "header_a.h" | ||
| #include "header_b.h" | ||
| int x = 1; | ||
| #include "header_c.h" | ||
|
|
||
| const char data[] = { | ||
| #embed "data.bin" | ||
| }; | ||
|
|
||
| #if __has_embed("data.bin") | ||
| int has_embed_found = 1; | ||
| #endif | ||
|
|
||
| #if __has_embed("no_such_file.bin") | ||
| int has_embed_not_found = 1; | ||
| #endif | ||
|
|
||
| int main() { | ||
| return a + b + c; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| @pytest.mark.workspace("document_links") | ||
| async def test_document_links_with_pch(client, workspace): | ||
| uri, content = await client.open_and_wait(workspace / "main.cpp") | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| links = await client.document_links(uri) | ||
|
|
||
| assert links is not None, "document_links returned None" | ||
|
|
||
| targets = sorted(Path(link.target).name for link in links) | ||
| assert targets == [ | ||
| "data.bin", | ||
| "data.bin", | ||
| "header_a.h", | ||
| "header_b.h", | ||
| "header_c.h", | ||
| ], f"Unexpected targets: {targets}" | ||
|
|
||
| client.close(uri) | ||
|
|
||
|
|
||
| @pytest.mark.workspace("document_links") | ||
| async def test_document_links_pch_portion(client, workspace): | ||
| uri, _ = await client.open_and_wait(workspace / "main.cpp") | ||
| links = await client.document_links(uri) | ||
|
|
||
| pch_links = [link for link in links if link.range.start.line < 2] | ||
| assert len(pch_links) == 2, ( | ||
| f"Expected 2 PCH links (lines 0-1), got {len(pch_links)}" | ||
| ) | ||
|
|
||
| pch_targets = sorted(Path(link.target).name for link in pch_links) | ||
| assert pch_targets == ["header_a.h", "header_b.h"] | ||
|
|
||
| client.close(uri) | ||
|
|
||
|
|
||
| @pytest.mark.workspace("document_links") | ||
| async def test_document_links_main_portion(client, workspace): | ||
| uri, _ = await client.open_and_wait(workspace / "main.cpp") | ||
| links = await client.document_links(uri) | ||
|
|
||
| main_links = [link for link in links if link.range.start.line >= 2] | ||
| assert len(main_links) == 3, ( | ||
| f"Expected 3 main-file links (lines 3, 6, 9), got {len(main_links)}" | ||
| ) | ||
|
|
||
| main_targets = sorted(Path(link.target).name for link in main_links) | ||
| assert main_targets == ["data.bin", "data.bin", "header_c.h"] | ||
|
|
||
| client.close(uri) | ||
|
|
||
|
|
||
| @pytest.mark.workspace("document_links") | ||
| async def test_document_links_embed(client, workspace): | ||
| uri, _ = await client.open_and_wait(workspace / "main.cpp") | ||
| links = await client.document_links(uri) | ||
|
|
||
| embed_links = [ | ||
| link | ||
| for link in links | ||
| if Path(link.target).name == "data.bin" and link.range.start.line == 6 | ||
| ] | ||
| assert len(embed_links) == 1, ( | ||
| f"Expected 1 embed link at line 6, got {len(embed_links)}" | ||
| ) | ||
|
|
||
| client.close(uri) | ||
|
|
||
|
|
||
| @pytest.mark.workspace("document_links") | ||
| async def test_document_links_has_embed_exists(client, workspace): | ||
| uri, _ = await client.open_and_wait(workspace / "main.cpp") | ||
| links = await client.document_links(uri) | ||
|
|
||
| has_embed_links = [ | ||
| link | ||
| for link in links | ||
| if Path(link.target).name == "data.bin" and link.range.start.line == 9 | ||
| ] | ||
| assert len(has_embed_links) == 1, ( | ||
| f"Expected 1 has_embed link at line 9, got {len(has_embed_links)}" | ||
| ) | ||
|
|
||
| client.close(uri) | ||
|
|
||
|
|
||
| @pytest.mark.workspace("document_links") | ||
| async def test_document_links_has_embed_missing(client, workspace): | ||
| uri, _ = await client.open_and_wait(workspace / "main.cpp") | ||
| links = await client.document_links(uri) | ||
|
|
||
| missing_links = [ | ||
| link for link in links if Path(link.target).name == "no_such_file.bin" | ||
| ] | ||
| assert len(missing_links) == 0, ( | ||
| f"Expected 0 links for non-existent file, got {len(missing_links)}" | ||
| ) | ||
|
|
||
| client.close(uri) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.