From 8dd751a70f16db88ba8962179d5b5f44f7362c36 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Mon, 19 Jun 2017 23:31:34 -0700 Subject: [PATCH] Fix completion for items with underscores. --- src/working_files.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/working_files.cc b/src/working_files.cc index 33589f9c..afef44e9 100644 --- a/src/working_files.cc +++ b/src/working_files.cc @@ -222,7 +222,7 @@ lsPosition WorkingFile::FindStableCompletionSource(lsPosition position, bool* is while (offset > 0) { char c = buffer_content[offset - 1]; - if (!isalnum(c)) { + if (!isalnum(c) && c != '_') { // Global completion is everything except for dot (.), arrow (->), and // double colon (::) if (c == '.') @@ -421,4 +421,18 @@ TEST_CASE("existing completion") { REQUIRE(existing_completion == "asdf"); } +TEST_CASE("existing completion underscore") { + // TODO: remove trailing space in ABC_DEF. Lexing doesn't work correctly if done at the end of input. + WorkingFile f("foo.cc", "ABC_DEF "); + bool is_global_completion; + std::string existing_completion; + + f.FindStableCompletionSource(CharPos(f, 'C'), &is_global_completion, &existing_completion); + REQUIRE(existing_completion == "AB"); + f.FindStableCompletionSource(CharPos(f, '_'), &is_global_completion, &existing_completion); + REQUIRE(existing_completion == "ABC"); + f.FindStableCompletionSource(CharPos(f, 'D'), &is_global_completion, &existing_completion); + REQUIRE(existing_completion == "ABC_"); +} + TEST_SUITE_END(); \ No newline at end of file