2018-10-22 23:53:20 -05:00
|
|
|
# This function is compatible with clang, clang++, and variations thereof, and is shared
|
|
|
|
# by clang.fish and clang++.fish.
|
2024-01-22 07:42:45 +01:00
|
|
|
# We dynamically query the head at `(commandline -x)[1]` to get the correct completions.
|
2020-01-22 23:17:37 +09:00
|
|
|
function __fish_complete_clang
|
2019-05-05 12:09:25 +02:00
|
|
|
# If the result is for a value, clang only prints the value, so completions
|
|
|
|
# for `-std=` print `c++11` and not `-std=c++11` like we need. See #4174.
|
|
|
|
set -l prefix (commandline -ct | string replace -fr -- '^(.*=)[^=]*' '$1')
|
2018-10-22 23:53:20 -05:00
|
|
|
|
2019-05-05 12:09:25 +02:00
|
|
|
# Don't hard-code the name of the clang binary
|
2024-01-22 07:42:45 +01:00
|
|
|
set -l clang (commandline -xp)[1]
|
2019-05-05 12:09:25 +02:00
|
|
|
# first get the completions from clang, with the prefix separated from the value by a comma
|
2019-11-16 14:50:54 +08:00
|
|
|
$clang --autocomplete=(commandline -ct | string unescape | string replace -- "$prefix" "$prefix,") 2>/dev/null |
|
2020-08-17 11:43:02 +02:00
|
|
|
# and put it in a format that fish understands
|
|
|
|
string replace -r -- '^([^ ]+)\s*(.*)' "$prefix\$1\t\$2"
|
2018-10-22 23:53:20 -05:00
|
|
|
end
|