From fab0b36fffea13f72993167d94c14d352eb33cb3 Mon Sep 17 00:00:00 2001 From: Levon Date: Sun, 29 Dec 2024 01:27:11 +0300 Subject: [PATCH 1/2] clangd issue workaround - lower_drive_if_win32 --- refresh.template.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/refresh.template.py b/refresh.template.py index 194f365e..a1eaaed8 100644 --- a/refresh.template.py +++ b/refresh.template.py @@ -1147,6 +1147,17 @@ def _convert_compile_commands(aquery_output): ) as threadpool: outputs = threadpool.map(_get_cpp_command_for_files, aquery_output.actions) + # Workaround for: https://github.com/clangd/clangd/issues/108 + # Fixes clangd's ambiguous path handling which cause a broken f2-editing + def lower_drive_if_win32(dir): + if sys.platform == 'win32': + drive, path = os.path.splitdrive(dir) + dir = os.path.join(str(drive).lower(), path) + + return dir + + dir = lower_drive_if_win32(os.environ["BUILD_WORKSPACE_DIRECTORY"]) + # Yield as compile_commands.json entries header_files_already_written = set() for source_files, header_files, compile_command_args in outputs: @@ -1167,7 +1178,7 @@ def _convert_compile_commands(aquery_output): # Using `arguments' instead of 'command' because it's now preferred by clangd. Heads also that shlex.join doesn't work for windows cmd, so you'd need to use windows_list2cmdline if we ever switched back. For more, see https://github.com/hedronvision/bazel-compile-commands-extractor/issues/8#issuecomment-1090262263 'arguments': compile_command_args, # Bazel gotcha warning: If you were tempted to use `bazel info execution_root` as the build working directory for compile_commands...search ImplementationReadme.md to learn why that breaks. - 'directory': os.environ["BUILD_WORKSPACE_DIRECTORY"], + 'directory': dir, } From c336a8bbff5faaa52de8a46187a44acaca5a238c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 28 Dec 2024 22:49:28 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- refresh.template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/refresh.template.py b/refresh.template.py index a1eaaed8..5095f613 100644 --- a/refresh.template.py +++ b/refresh.template.py @@ -1155,7 +1155,7 @@ def lower_drive_if_win32(dir): dir = os.path.join(str(drive).lower(), path) return dir - + dir = lower_drive_if_win32(os.environ["BUILD_WORKSPACE_DIRECTORY"]) # Yield as compile_commands.json entries