Skip to content

Commit a7cee28

Browse files
16bit-ykikoclaude
andcommitted
fix: replace host source arg by identity, fix unused variables
- Replace host source file in args by matching against CDB file entry instead of removing last positional arg. Fixes "clang++ -c main.cpp -o main.o" case where the old logic would strip -o's argument and leave main.cpp in argv. - Remove unused main_uri bindings in 3 tests (Ruff RUF059) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 79c9aae commit a7cee28

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

src/server/master_server.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -756,20 +756,17 @@ bool MasterServer::fill_compile_args(llvm::StringRef path,
756756
directory = host_ctx.directory.str();
757757
arguments.clear();
758758

759-
// Copy host arguments, replacing the source file path (last non-flag arg)
760-
// with the header file path, so the compiler processes the header in context.
761-
auto num_args = host_ctx.arguments.size();
762-
std::size_t copy_count = num_args;
763-
if(copy_count > 0) {
764-
llvm::StringRef last(host_ctx.arguments[copy_count - 1]);
765-
if(!last.starts_with("-"))
766-
copy_count -= 1;
767-
}
768-
for(std::size_t i = 0; i < copy_count; ++i) {
769-
arguments.emplace_back(host_ctx.arguments[i]);
770-
}
771-
// Append the header file path as the source file.
772-
arguments.emplace_back(path);
759+
// Copy host arguments, replacing the host source file path with the header
760+
// file path. We identify the host source by matching against the CDB file
761+
// entry rather than guessing based on positional order, so that entries like
762+
// "clang++ -c main.cpp -o main.o" are handled correctly.
763+
for(auto& arg: host_ctx.arguments) {
764+
if(llvm::StringRef(arg) == host_path) {
765+
arguments.emplace_back(path);
766+
} else {
767+
arguments.emplace_back(arg);
768+
}
769+
}
773770

774771
// Inject the preamble so the compiler sees all context code that normally
775772
// precedes this header in the host translation unit.

tests/integration/test_header_context.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def _get(obj, key, default=None):
3232
@pytest.mark.workspace("header_context")
3333
async def test_query_context_returns_host_sources(client, workspace):
3434
"""clice/queryContext on a header should return source files that include it."""
35-
main_uri, _ = await client.open_and_wait(workspace / "main.cpp")
35+
await client.open_and_wait(workspace / "main.cpp")
3636

3737
utils_h = workspace / "utils.h"
3838
utils_uri, _ = client.open(utils_h)
@@ -71,7 +71,7 @@ async def test_query_context_source_file_returns_cdb_entries(client, workspace):
7171
@pytest.mark.workspace("header_context")
7272
async def test_current_context_default_null(client, workspace):
7373
"""clice/currentContext should return null context by default."""
74-
main_uri, _ = await client.open_and_wait(workspace / "main.cpp")
74+
await client.open_and_wait(workspace / "main.cpp")
7575

7676
utils_h = workspace / "utils.h"
7777
utils_uri, _ = client.open(utils_h)
@@ -190,7 +190,7 @@ async def test_full_context_flow(client, workspace):
190190
async def test_deep_nested_header_context(client, workspace):
191191
"""queryContext on a deeply nested header (main.cpp -> utils.h -> inner.h)
192192
should still find main.cpp as the host source."""
193-
main_uri, _ = await client.open_and_wait(workspace / "main.cpp")
193+
await client.open_and_wait(workspace / "main.cpp")
194194

195195
inner_h = workspace / "inner.h"
196196
inner_uri, _ = client.open(inner_h)

0 commit comments

Comments
 (0)