3 public class LanguageClientJavascript : LanguageClient {
6 public LanguageClientJavascript(Project.Project project)
8 // extend versions will proably call initialize to start and connect to server.
13 public override void initialize_server() {
14 GLib.debug("initialize javascript server");
16 public override void startServer()
23 public new bool isReady()
27 public new void document_open (JsRender.JsRender file)
30 Javascript.singleton().validate(file.toSourceCode(), file );
31 BuilderApplication.updateCompileResults();
34 public new void document_save (JsRender.JsRender file)
36 Javascript.singleton().validate(file.toSourceCode(), file );
37 BuilderApplication.updateCompileResults();
39 public new void document_change (JsRender.JsRender file )
41 Javascript.singleton().validate(file.toSourceCode(), file );
42 BuilderApplication.updateCompileResults();
45 public async Lsp.CompletionList? completion(JsRender.JsRender file, int line, int offset , int triggerType = 1) throws GLib.Error
48 var ret = new Lsp.CompletionList();
51 var ar = file.toSource().split("\n");
52 var ln = line >= ar.length ? "" : ar[line];
53 if (ln.length >= offset) {
57 for (var i = offset; i > 0; i--) {
58 GLib.debug("check char %c", ln[i]);
59 if (ln[i].isalpha() || ln[i] == '.') {
65 var complete_string = ln.substring(start, offset - start);
66 GLib.debug("complete string = %s", complete_string);
74 // this. (based on the node type)
75 // this.xxx // Node and any determination.
77 // keywords... // text does not contains "."
79 if (!complete_string.contains(".")) {
80 // string does not have a '.'
81 // offer up this / Roo / javascript keywords... / look for var string = .. in the code..
82 for(var i = 0; i < JsRender.Lang.match_strings.size ; i++) {
83 var str = JsRender.Lang.match_strings.get(i);
84 var sci = new Lsp.CompletionItem.keyword(str, str, "keywords : %s".printf(str));
91 if (complete_string != "Roo" && "Roo".has_prefix(complete_string) ) {
92 // should we ignore exact matches... ???
93 var sci = new Lsp.CompletionItem.keyword("Roo", "Roo", "Roo - A Roo class" );
98 if (complete_string != "_this" && "_this".has_prefix( complete_string) ) {
99 // should we ignore exact matches... ???
101 var sci = new Lsp.CompletionItem.keyword("_this", "_this", "Reference to the global pointer to the files main class instance");
108 // got at least one ".".
109 var parts = complete_string.split(".");
111 var cur_instance = false;
112 if (parts[0] == "this") {
113 // work out from the node, what the type is...
114 // fetch node from element.
115 //if (node == null) {
116 GLib.debug("node is empty - no return\n");
117 return ret; // no idea..
119 //curtype = node.fqn();
120 //cur_instance = true;
122 if (parts[0] == "Roo") {
124 cur_instance = false;
127 var prevbits = parts[0] + ".";
128 for(var i =1; i < parts.length; i++) {
129 GLib.debug("matching %d/%d\n", i, parts.length);
131 var is_last = i == parts.length -1;
132 // look up all the properties of the type...
133 var cls = this.project.palete.getClass(curtype);
135 GLib.debug("could not get class of curtype %s\n", curtype);
141 // only exact matches from here on...
143 if (cls.props.has_key(parts[i])) {
144 var prop = cls.props.get(parts[i]);
145 if (prop.type.index_of(".",0) > -1) {
146 // type is another roo object..
148 prevbits += parts[i] + ".";
156 // check methods?? - we do not export that at present..
157 return ret; //no idea...
161 //look for child classes.
162 var citer = this.project.palete.classes.map_iterator();
164 while (citer.next()) {
165 var scls = citer.get_key();
166 var look = prevbits + parts[i];
167 if (scls.index_of(look,0) != 0) {
170 // got a starting match..
172 cur_instance = false;
179 prevbits += parts[i] + ".";
182 // got to the last element..
183 GLib.debug("Got last element\n");
184 if (curtype == "") { // should not happen.. we would have returned already..
187 GLib.debug("Got last element type %s\n",curtype);
189 GLib.debug("matching instance");
190 // it's a static reference..
191 var citer = this.project.palete.classes.map_iterator();
192 while (citer.next()) {
193 var scls = citer.get_key();
194 var look = prevbits + parts[i];
195 if (parts[i].length > 0 && scls.index_of(look,0) != 0) {
198 var sci = new Lsp.CompletionItem.keyword(scls,scls, "doc??" );
205 GLib.debug("matching property");
209 var citer = cls.methods.map_iterator();
210 while (citer.next()) {
211 var prop = citer.get_value();
212 // does the name start with ...
213 if (parts[i].length > 0 && prop.name.index_of(parts[i],0) != 0) {
216 // got a matching property...
219 var sci = new Lsp.CompletionItem.keyword( prevbits + prop.name + "(", prop.name + "(" , prop.doctxt );
226 // get the properties / methods and subclasses.. of cls..
227 // we have cls.. - see if the string matches any of the properties..
228 citer = cls.props.map_iterator();
229 while (citer.next()) {
230 var prop = citer.get_value();
231 // does the name start with ...
232 if (parts[i].length > 0 && prop.name.index_of(parts[i],0) != 0) {
236 var sci = new Lsp.CompletionItem.keyword( prevbits + prop.name + "(", prop.name + "(" , prop.doctxt );