Skip to content

Commit c1ddcf2

Browse files
committed
Add token::GenerateCompletion
1 parent c6414c5 commit c1ddcf2

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

src/librustdoc/html/highlight.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader,
171171

172172
token::Lifetime(..) => "lifetime",
173173
token::DocComment(..) => "doccomment",
174-
token::Underscore | token::Eof | token::Interpolated(..) |
174+
token::Underscore | token::Eof | token::GenerateCompletion |
175+
token::Interpolated(..) |
175176
token::MatchNt(..) | token::SubstNt(..) => "",
176177
};
177178

src/libsyntax/parse/lexer/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ impl<'a> Reader for StringReader<'a> {
8484
fn is_eof(&self) -> bool { self.curr.is_none() }
8585
/// Return the next token. EFFECT: advances the string_reader.
8686
fn next_token(&mut self) -> TokenAndSpan {
87+
if let Some(pos) = self.complete_at {
88+
if self.peek_span.lo >= pos {
89+
self.complete_at = None;
90+
return TokenAndSpan {
91+
tok: token::GenerateCompletion,
92+
sp: codemap::mk_sp(pos, pos),
93+
}
94+
}
95+
}
8796
let ret_val = TokenAndSpan {
8897
tok: replace(&mut self.peek_tok, token::Underscore),
8998
sp: self.peek_span,

src/libsyntax/parse/token.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ pub enum Token {
161161
/// A macro variable with special meaning.
162162
SpecialVarNt(SpecialMacroVar),
163163

164+
/* For completion */
165+
GenerateCompletion,
166+
164167
// Junk. These carry no data because we don't really care about the data
165168
// they *would* carry, and don't really want to allocate a new ident for
166169
// them. Instead, users could extract that from the associated span.

src/libsyntax/print/pprust.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,16 @@ pub fn token_to_string(tok: &Token) -> String {
294294

295295
token::SpecialVarNt(var) => format!("${}", var.as_str()),
296296

297+
// A proofreading mark is chosen, because the compiler is proofreading
298+
// your code.
299+
//
300+
// U+2038 CARET or U+2041 CARET INSERTION POINT would be better,
301+
// but both have poor font support. Neither are supported by
302+
// Courier New, the default monospaced font on Windows, for example.
303+
token::GenerateCompletion => {
304+
"\u{B6}".to_string() // PILCROW SIGN
305+
}
306+
297307
token::Interpolated(ref nt) => match *nt {
298308
token::NtExpr(ref e) => expr_to_string(&**e),
299309
token::NtMeta(ref e) => meta_item_to_string(&**e),

0 commit comments

Comments
 (0)