Skip to content

Commit f16af3e

Browse files
authored
Merge pull request #1017 from BenPH/emoji-completions
Add emoji completions
2 parents f7bed77 + 55ca842 commit f16af3e

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/requests/completions.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function textDocument_completion_request(params::CompletionParams, server::Langu
5252

5353
if pt isa CSTParser.Tokens.Token && pt.kind == CSTParser.Tokenize.Tokens.BACKSLASH
5454
latex_completions(string("\\", CSTParser.Tokenize.untokenize(t)), state)
55-
elseif ppt isa CSTParser.Tokens.Token && ppt.kind == CSTParser.Tokenize.Tokens.BACKSLASH && pt isa CSTParser.Tokens.Token && pt.kind === CSTParser.Tokens.CIRCUMFLEX_ACCENT
55+
elseif ppt isa CSTParser.Tokens.Token && ppt.kind == CSTParser.Tokenize.Tokens.BACKSLASH && pt isa CSTParser.Tokens.Token && (pt.kind === CSTParser.Tokens.CIRCUMFLEX_ACCENT || pt.kind === CSTParser.Tokens.COLON)
5656
latex_completions(string("\\", CSTParser.Tokenize.untokenize(pt), CSTParser.Tokenize.untokenize(t)), state)
5757
elseif t isa CSTParser.Tokens.Token && t.kind == CSTParser.Tokenize.Tokens.COMMENT
5858
partial = is_latex_comp(t.val, state.offset - t.startbyte)
@@ -106,7 +106,7 @@ function get_partial_completion(state::CompletionState)
106106
end
107107

108108
function latex_completions(partial::String, state::CompletionState)
109-
for (k, v) in REPL.REPLCompletions.latex_symbols
109+
for (k, v) in Iterators.flatten((REPL.REPLCompletions.latex_symbols, REPL.REPLCompletions.emoji_symbols))
110110
if is_completion_match(string(k), partial)
111111
# t1 = TextEdit(Range(state.doc, (state.offset - sizeof(partial)):state.offset), v)
112112
add_completion_item(state, CompletionItem(k, 11, missing, v, v, missing, missing, missing, missing, missing, missing, texteditfor(state, partial, v), missing, missing, missing, missing))
@@ -345,13 +345,15 @@ is_latex_comp_char(c::Char) = UInt32(c) <= typemax(UInt8) ? is_latex_comp_char(U
345345
function is_latex_comp_char(u)
346346
# Checks whether a Char (represented as a UInt8) is in the set of those those used to trigger
347347
# latex completions.
348-
# from: UInt8.(sort!(unique(prod([k[2:end] for (k,_) in REPL.REPLCompletions.latex_symbols]))))
348+
# from: UInt8.(sort!(unique(prod([k[2:end] for (k,_) in Iterators.flatten((REPL.REPLCompletions.latex_symbols, REPL.REPLCompletions.emoji_symbols))]))))
349+
u === 0x21 ||
349350
u === 0x28 ||
350351
u === 0x29 ||
351352
u === 0x2b ||
352353
u === 0x2d ||
353354
u === 0x2f ||
354355
0x30 <= u <= 0x39 ||
356+
u === 0x3a ||
355357
u === 0x3d ||
356358
0x41 <= u <= 0x5a ||
357359
u === 0x5e ||

test/requests/completions.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ completion_test(line, char) = LanguageServer.textDocument_completion_request(Lan
88
"\\therefor"
99
\"\"\"\\therefor\"\"\"
1010
^\\therefor
11+
\\:water_buffal
1112
""")
1213
@test completion_test(0, 9).items[1].textEdit.newText == ""
1314
@test completion_test(0, 9).items[1].textEdit.range == LanguageServer.Range(0, 0, 0, 9)
@@ -26,6 +27,9 @@ completion_test(line, char) = LanguageServer.textDocument_completion_request(Lan
2627

2728
@test completion_test(5, 10).items[1].textEdit.newText == ""
2829
@test completion_test(5, 10).items[1].textEdit.range == LanguageServer.Range(5, 1, 5, 10)
30+
31+
@test completion_test(6, 14).items[1].textEdit.newText == "🐃"
32+
@test completion_test(6, 14).items[1].textEdit.range == LanguageServer.Range(6, 0, 6, 14)
2933
end
3034

3135
@testset "path completions" begin

0 commit comments

Comments
 (0)