What i am doing right now is to identify the current scope of the cursor point and then provide the completions using a hashmap according to the scope.
HashMap<String,String[]> program =new HashMap<String, String[]>(){{
put("function", new String[]{"Function", "function functionName(){\n\t\n}}"});
put("if", new String[]{"If", "if (true) {\n\t\n}"});
put("try", new String[]{"Try", "try {\n\t\n}}catch(err) {\nconsole.log(err)}"});
put("class", new String[]{"Class", "Class className {\n\t\n}}"});
put("for", new String[]{"For", "for (var i=0; i<10; i++) {\n\t\n}}"});
put("while", new String[]{"While", "while (true) {\n\t\n}}"});
put("do", new String[]{"Do", "do {\n\t\n}}while (true);"});
put("var", new String[]{"Var", "var"});
put("let", new String[]{"Let", "let"});
put("const", new String[]{"Const", "const"});
put("switch", new String[]{"Switch", "switch(expression) {\n" +
" case x:\n" +
" // code block\n" +
" break;\n" +
" case y:\n" +
" // code block\n" +
" break;\n" +
" default:\n" +
" // code block\n" +
" }"});
}};
HashMap<String,String[]> sourceElement =new HashMap<String, String[]>(){{
put("function", new String[]{"Function", "function functionName(){\n\t\n}}"});
put("if", new String[]{"If", "if (true) {\n\t\n}"});
put("try", new String[]{"Try", "try {\n\t\n}}catch(err) {\nconsole.log(err)}"});
and then use swith to select the correct hashmap.
JsonObject mainObj = new JsonObject();
switch(finalScope) {
case "program":
mainObj.add("re",generateArray(program));
break;
case "sourceelement":
mainObj.add("re",generateArray(sourceElement));
like wise. what i want to know is is there a good way than thisto do tha task. I am using antlr4 to parse the code. and write my lsp using the java