79 snapshot.convert(Text.Range(former_caret - 1, former_caret)) |
79 snapshot.convert(Text.Range(former_caret - 1, former_caret)) |
80 } |
80 } |
81 |
81 |
82 def completion(caret_pos: Line.Position, caret: Text.Offset): List[Protocol.CompletionItem] = |
82 def completion(caret_pos: Line.Position, caret: Text.Offset): List[Protocol.CompletionItem] = |
83 { |
83 { |
84 val caret_range = before_caret_range(caret) |
|
85 |
|
86 val history = Completion.History.empty |
|
87 val doc = model.content.doc |
84 val doc = model.content.doc |
88 |
85 val line = caret_pos.line |
89 val syntax_completion = |
86 doc.offset(Line.Position(line)) match { |
90 { |
87 case None => Nil |
91 val syntax = model.syntax() |
88 case Some(line_start) => |
92 val context = language_context(caret_range) getOrElse syntax.language_context |
89 val history = Completion.History.empty |
93 |
90 val caret_range = before_caret_range(caret) |
94 val line = caret_pos.line |
91 |
95 doc.offset(Line.Position(line)) match { |
92 val syntax = model.syntax() |
96 case Some(line_start) => |
93 val syntax_completion = |
97 syntax.completion.complete(history, unicode = false, explicit = true, |
94 syntax.completion.complete(history, unicode = false, explicit = true, |
98 line_start, doc.lines(line).text, caret - line_start, context) |
95 line_start, doc.lines(line).text, caret - line_start, |
99 case None => None |
96 language_context(caret_range) getOrElse syntax.language_context) |
100 } |
97 |
101 } |
98 val (no_completion, semantic_completion) = |
102 |
99 rendering.semantic_completion_result( |
103 val (no_completion, semantic_completion) = |
100 history, false, syntax_completion.map(_.range), caret_range, doc.try_get_text(_)) |
104 rendering.semantic_completion_result( |
101 |
105 history, false, syntax_completion.map(_.range), caret_range, doc.try_get_text(_)) |
102 if (no_completion) Nil |
106 |
103 else { |
107 if (no_completion) Nil |
104 Completion.Result.merge(history, semantic_completion, syntax_completion) match { |
108 else { |
105 case None => Nil |
109 Completion.Result.merge(history, semantic_completion, syntax_completion) match { |
106 case Some(result) => |
110 case None => Nil |
107 result.items.map(item => |
111 case Some(result) => |
108 Protocol.CompletionItem( |
112 result.items.map(item => |
109 label = item.replacement, |
113 Protocol.CompletionItem( |
110 detail = Some(item.description.mkString(" ")), |
114 label = item.replacement, |
111 range = Some(doc.range(item.range)))) |
115 detail = Some(item.description.mkString(" ")), |
112 } |
116 range = Some(doc.range(item.range)))) |
113 } |
117 } |
|
118 } |
114 } |
119 } |
115 } |
120 |
116 |
121 |
117 |
122 /* diagnostics */ |
118 /* diagnostics */ |