Repository navigation
feat: integrate PCH into MasterServer build drain #381
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
5 commits
Select commit
Hold shift + click to select a range
c539a44
feat: integrate PCH into MasterServer build drain and stateless forwa…
16bit-ykiko e0b4ec8
fix: address CodeRabbit review comments
16bit-ykiko 00fd47e
fix: multiple PCH correctness issues found in self-review
16bit-ykiko 8330d0c
fix: address new CodeRabbit review findings
16bit-ykiko f73ca4f
style: format compilation_tests.cpp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #pragma once | ||
|
|
||
| struct Point { | ||
| int x; | ||
| int y; | ||
| }; | ||
|
|
||
| int add(int a, int b); |
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,11 @@ | ||
| #include "common.h" | ||
|
|
||
| int add(int a, int b) { | ||
| return a + b; | ||
| } | ||
|
|
||
| int main() { | ||
| Point p{1, 2}; | ||
| int result = add(p.x, p.y); | ||
| return result; | ||
| } |
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,7 @@ | ||
| int square(int x) { | ||
| return x * x; | ||
| } | ||
|
|
||
| int main() { | ||
| return square(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,104 @@ | ||
| """Integration tests for PCH (precompiled header) functionality in MasterServer.""" | ||
|
|
||
| import asyncio | ||
|
|
||
| import pytest | ||
| from lsprotocol.types import ( | ||
| CompletionParams, | ||
| DidChangeTextDocumentParams, | ||
| DidCloseTextDocumentParams, | ||
| HoverParams, | ||
| Position, | ||
| TextDocumentContentChangeWholeDocument, | ||
| TextDocumentIdentifier, | ||
| VersionedTextDocumentIdentifier, | ||
| ) | ||
|
|
||
|
|
||
| def _doc(uri: str) -> TextDocumentIdentifier: | ||
| return TextDocumentIdentifier(uri=uri) | ||
|
|
||
|
|
||
| @pytest.mark.workspace("pch_test") | ||
|
16bit-ykiko marked this conversation as resolved.
|
||
| async def test_pch_diagnostics_on_open(client, workspace): | ||
| """Opening a file with #include should trigger PCH build and return clean diagnostics.""" | ||
| uri, _ = await client.open_and_wait(workspace / "main.cpp") | ||
| assert uri in client.diagnostics | ||
| # main.cpp is well-formed, so diagnostics list should be empty (no errors). | ||
| diags = client.diagnostics[uri] | ||
| assert len(diags) == 0, f"Expected no diagnostics, got: {diags}" | ||
| client.text_document_did_close(DidCloseTextDocumentParams(text_document=_doc(uri))) | ||
|
|
||
|
|
||
| @pytest.mark.workspace("pch_test") | ||
| async def test_pch_body_edit_triggers_recompile(client, workspace): | ||
| """Editing only the body (not the preamble) should trigger recompilation.""" | ||
| uri, content = await client.open_and_wait(workspace / "main.cpp") | ||
|
|
||
| # Edit only the function body — preamble (#include "common.h") unchanged. | ||
| new_content = content.replace("return result;", "return result + 1;") | ||
| event = client.wait_for_diagnostics(uri) | ||
| client.text_document_did_change( | ||
| DidChangeTextDocumentParams( | ||
| text_document=VersionedTextDocumentIdentifier(uri=uri, version=1), | ||
| content_changes=[TextDocumentContentChangeWholeDocument(text=new_content)], | ||
| ) | ||
| ) | ||
| # The key assertion: recompilation completes (diagnostics event fires). | ||
| await asyncio.wait_for(event.wait(), timeout=30.0) | ||
| assert uri in client.diagnostics | ||
| client.text_document_did_close(DidCloseTextDocumentParams(text_document=_doc(uri))) | ||
|
|
||
|
|
||
| @pytest.mark.workspace("pch_test") | ||
| async def test_no_pch_for_no_includes(client, workspace): | ||
| """A file with no #include directives should compile without PCH.""" | ||
| uri, _ = await client.open_and_wait(workspace / "no_includes.cpp") | ||
| assert uri in client.diagnostics | ||
| diags = client.diagnostics[uri] | ||
| assert len(diags) == 0, f"Expected no diagnostics, got: {diags}" | ||
| client.text_document_did_close(DidCloseTextDocumentParams(text_document=_doc(uri))) | ||
|
|
||
|
|
||
| @pytest.mark.workspace("pch_test") | ||
| async def test_hover_on_local_symbol(client, workspace): | ||
| """Hover on a locally defined symbol should work when PCH is active.""" | ||
| uri, _ = await client.open_and_wait(workspace / "main.cpp") | ||
|
|
||
| # Hover over "add" on line 2 (0-indexed): "int add(int a, int b) {" | ||
| result = await client.text_document_hover_async( | ||
| HoverParams(text_document=_doc(uri), position=Position(line=2, character=4)) | ||
| ) | ||
| assert result is not None | ||
| client.text_document_did_close(DidCloseTextDocumentParams(text_document=_doc(uri))) | ||
|
|
||
|
|
||
| @pytest.mark.workspace("pch_test") | ||
| async def test_completion_with_pch(client, workspace): | ||
| """Completion should see symbols from PCH headers.""" | ||
| uri, content = await client.open_and_wait(workspace / "main.cpp") | ||
|
|
||
| # Add a line that starts typing "Poi" to trigger completion for Point. | ||
| new_content = content + "\nPoi" | ||
| lines = new_content.split("\n") | ||
| last_line = len(lines) - 1 | ||
|
|
||
| event = client.wait_for_diagnostics(uri) | ||
| client.text_document_did_change( | ||
| DidChangeTextDocumentParams( | ||
| text_document=VersionedTextDocumentIdentifier(uri=uri, version=1), | ||
| content_changes=[TextDocumentContentChangeWholeDocument(text=new_content)], | ||
| ) | ||
| ) | ||
| # Brief wait for the change to be processed. | ||
| await asyncio.sleep(1.0) | ||
|
|
||
| result = await client.text_document_completion_async( | ||
| CompletionParams( | ||
| text_document=_doc(uri), | ||
| position=Position(line=last_line, character=3), | ||
| ) | ||
| ) | ||
| # Completion should return results. | ||
| assert result is not None | ||
| client.text_document_did_close(DidCloseTextDocumentParams(text_document=_doc(uri))) | ||
Oops, something went wrong.
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.