|
1 | 1 | #![cfg(target_arch = "wasm32")]
|
2 | 2 | #![allow(non_snake_case)]
|
3 | 3 |
|
4 |
| -use ra_ide_api::{Analysis, CompletionItemKind, FileId, FilePosition, LineCol, Severity}; |
| 4 | +use ra_ide_api::{ |
| 5 | + Analysis, CompletionItemKind, FileId, FilePosition, InsertTextFormat, LineCol, Severity, |
| 6 | +}; |
5 | 7 | use ra_syntax::{SyntaxKind, TextRange};
|
6 | 8 | use wasm_bindgen::prelude::*;
|
7 | 9 |
|
| 10 | +mod conv; |
| 11 | +use conv::*; |
8 | 12 | mod return_types;
|
9 | 13 | use return_types::*;
|
10 | 14 |
|
@@ -89,40 +93,33 @@ impl WorldState {
|
89 | 93 | }
|
90 | 94 |
|
91 | 95 | pub fn completions(&self, line_number: u32, column: u32) -> JsValue {
|
92 |
| - let pos = self.file_pos(line_number, column); |
93 | 96 | log::warn!("completions");
|
| 97 | + let line_index = self.analysis.file_line_index(self.file_id).unwrap(); |
| 98 | + let pos = Position { line_number, column }.conv_with((&line_index, self.file_id)); |
| 99 | + |
94 | 100 | let res = match self.analysis.completions(pos).unwrap() {
|
95 | 101 | Some(items) => items,
|
96 | 102 | None => return JsValue::NULL,
|
97 | 103 | };
|
98 | 104 |
|
| 105 | + log::warn!("{:#?}", res); |
| 106 | + |
99 | 107 | let items: Vec<_> = res
|
100 | 108 | .into_iter()
|
101 | 109 | .map(|item| CompletionItem {
|
102 |
| - kind: match item.kind() { |
103 |
| - Some(CompletionItemKind::Snippet) => 25, |
104 |
| - Some(CompletionItemKind::Keyword) => 17, |
105 |
| - Some(CompletionItemKind::Module) => 8, |
106 |
| - Some(CompletionItemKind::Function) => 1, |
107 |
| - Some(CompletionItemKind::BuiltinType) => 6, |
108 |
| - Some(CompletionItemKind::Struct) => 6, |
109 |
| - Some(CompletionItemKind::Enum) => 15, |
110 |
| - Some(CompletionItemKind::EnumVariant) => 16, |
111 |
| - Some(CompletionItemKind::Binding) => 4, |
112 |
| - Some(CompletionItemKind::Field) => 3, |
113 |
| - Some(CompletionItemKind::Static) => 13, |
114 |
| - Some(CompletionItemKind::Const) => 14, |
115 |
| - Some(CompletionItemKind::Trait) => 7, |
116 |
| - Some(CompletionItemKind::TypeAlias) => 6, |
117 |
| - Some(CompletionItemKind::Method) => 0, |
118 |
| - Some(CompletionItemKind::TypeParam) => 24, |
119 |
| - Some(CompletionItemKind::Macro) => 0, |
120 |
| - _ => 25, |
121 |
| - }, |
| 110 | + kind: item.kind().unwrap_or(CompletionItemKind::Struct).conv(), |
122 | 111 | label: item.label().to_string(),
|
123 | 112 | range: self.range(item.source_range()),
|
124 | 113 | detail: item.detail().map(|it| it.to_string()),
|
125 | 114 | insertText: item.text_edit().as_atoms()[0].insert.clone(),
|
| 115 | + insertTextRules: match item.insert_text_format() { |
| 116 | + InsertTextFormat::PlainText => CompletionItemInsertTextRule::None, |
| 117 | + InsertTextFormat::Snippet => CompletionItemInsertTextRule::InsertAsSnippet, |
| 118 | + }, |
| 119 | + documentation: item |
| 120 | + .documentation() |
| 121 | + .map(|doc| MarkdownString { value: doc.as_str().to_string() }), |
| 122 | + filterText: item.lookup().to_string(), |
126 | 123 | })
|
127 | 124 | .collect();
|
128 | 125 | serde_wasm_bindgen::to_value(&items).unwrap()
|
|
0 commit comments