为javascript的vscode扩展编写完成提供程序的最佳方法是什么

为javascript的vscode扩展编写完成提供程序的最佳方法是什么,javascript,language-server-protocol,Javascript,Language Server Protocol,我现在要做的是识别光标点的当前范围,然后根据范围使用hashmap提供补全 HashMap<String,String[]> program =new HashMap<String, String[]>(){{ put("function", new String[]{"Function", "function functionName(){\n\t\n}}"}); put("if", new String[]{"If",

我现在要做的是识别光标点的当前范围,然后根据范围使用hashmap提供补全

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)}"});

像智者一样。我想知道的是有没有比这更好的方法来完成这项任务。我正在使用antlr4解析代码。使用java来编写我的lsp,HashMap在我看来并不像JavaScript。@MauriceNino我是用java编写代码的。我需要编写一段代码来为javascript提供完整性(基本上类似于vscode)
JsonObject mainObj = new JsonObject();
        switch(finalScope) {
            case "program":
                mainObj.add("re",generateArray(program));
                break;
            case "sourceelement":
                mainObj.add("re",generateArray(sourceElement));