├── .DS_Store ├── .github └── workflows │ └── go.yml ├── .gitignore ├── CHANGELOG ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── docs ├── images │ ├── CodeCompletion.gif │ ├── DocmentSymbol.gif │ ├── FindReferences.gif │ ├── Format.gif │ ├── GlobalColor.gif │ ├── GotoDefinition.gif │ ├── Hover.gif │ ├── Install.gif │ ├── Install1.gif │ ├── Lsp.png │ ├── Lsp1.png │ ├── Nolsp.png │ ├── Nolsp1.png │ ├── Proxys.gif │ ├── RealTimeCheck.gif │ ├── SemanticCheck.gif │ ├── SyntaxCheck.gif │ ├── WorkspaceSymbol.gif │ ├── annotate │ │ ├── array_test1.png │ │ ├── array_test2.png │ │ ├── class_test1.png │ │ ├── class_test2.png │ │ ├── generic_test1.png │ │ ├── param_test1.png │ │ ├── return_test1.png │ │ ├── sample.png │ │ └── table_test1.png │ ├── clientexe.png │ ├── debug │ │ ├── addconfiguration.png │ │ ├── begindebug.png │ │ ├── debugattach.png │ │ ├── debugfile.png │ │ ├── debugfilerun.png │ │ ├── debugprinciple.png │ │ ├── debugsetting.gif │ │ ├── debugstruct.png │ │ ├── debugsuffix.png │ │ ├── debugways.png │ │ ├── go.png │ │ ├── launch.png │ │ ├── runonefile.gif │ │ ├── shortcutcmd.png │ │ └── socket.png │ ├── exe.png │ ├── go.png │ ├── install.png │ ├── json.png │ ├── logo.jpg │ ├── logo.png │ ├── logo_single.png │ ├── lsp2.png │ ├── running.png │ ├── socket.png │ └── src.png ├── jsonconfig │ ├── client │ │ └── luahelper.json │ ├── luahelper.json │ └── server │ │ └── luahelper.json └── manual │ ├── FAQ.html │ ├── FAQ.md │ ├── FAQ.pdf │ ├── Feature.md │ ├── annotate.md │ ├── annotate.pdf │ ├── config.md │ ├── debugPrinciple.md │ ├── debugsinglefile.md │ ├── debuguse.md │ ├── head.tex │ ├── introduction.md │ ├── mainsource.md │ ├── source.md │ ├── usedebug.docx │ ├── usedebug.md │ └── ~$edebug.docx ├── images ├── CodeCompletion.gif ├── DocmentSymbol.gif ├── FindReferences.gif ├── Format.gif ├── GlobalColor.gif ├── GotoDefinition.gif ├── Hover.gif ├── Install.gif ├── Lsp.png ├── Lsp1.png ├── Nolsp.png ├── Nolsp1.png ├── Proxys.gif ├── RealTimeCheck.gif ├── SemanticCheck.gif ├── SyntaxCheck.gif ├── WorkspaceSymbol.gif ├── annotate │ ├── array_test1.png │ ├── array_test2.png │ ├── class_test1.png │ ├── sample.png │ └── table_test1.png ├── clientexe.png ├── debug │ ├── addconfiguration.png │ ├── begindebug.png │ ├── debugattach.png │ ├── debugfile.png │ ├── debugfilerun.png │ ├── debugprinciple.png │ ├── debugsetting.gif │ ├── debugstruct.png │ ├── debugsuffix.png │ ├── debugways.png │ ├── go.png │ ├── launch.png │ ├── runonefile.gif │ ├── shortcutcmd.png │ └── socket.png ├── exe.png ├── install.png ├── json.png ├── lsp2.png ├── running.png └── src.png ├── luahelper-lsp ├── .idea │ └── .gitignore ├── .vscode │ ├── launch.json │ └── settings.json ├── build_mac_arm64.sh ├── go.mod ├── go.sum ├── langserver │ ├── check │ │ ├── analysis │ │ │ ├── analysis.go │ │ │ ├── analysis_block.go │ │ │ ├── analysis_check_assign.go │ │ │ ├── analysis_check_binop.go │ │ │ ├── analysis_check_const.go │ │ │ ├── analysis_check_enum.go │ │ │ ├── analysis_check_func.go │ │ │ ├── analysis_check_loc_var.go │ │ │ ├── analysis_check_table.go │ │ │ ├── analysis_exp.go │ │ │ ├── analysis_search.go │ │ │ ├── analysis_stat.go │ │ │ ├── analysis_util.go │ │ │ └── analysis_var_refer.go │ │ ├── annotation │ │ │ ├── annotateast │ │ │ │ ├── annotate_ast_common.go │ │ │ │ ├── annotate_fragment.go │ │ │ │ ├── annotate_sample.go │ │ │ │ ├── annotate_state.go │ │ │ │ ├── annotate_type.go │ │ │ │ └── annotate_util.go │ │ │ ├── annotatelexer │ │ │ │ ├── annotate_lexer.go │ │ │ │ ├── annotate_lexer_common.go │ │ │ │ └── annotate_token.go │ │ │ └── annotateparser │ │ │ │ ├── annotate_parser.go │ │ │ │ ├── annotate_parser_state.go │ │ │ │ ├── annotate_parser_test.go │ │ │ │ ├── annotate_parser_type.go │ │ │ │ └── string_util.go │ │ ├── check_all.go │ │ ├── check_color_file.go │ │ ├── check_common.go │ │ ├── check_find_var_refer.go │ │ ├── check_first_hanlde.go │ │ ├── check_for_type.go │ │ ├── check_lsp_annotate.go │ │ ├── check_lsp_annotate_complete.go │ │ ├── check_lsp_complete.go │ │ ├── check_lsp_define.go │ │ ├── check_lsp_filechange.go │ │ ├── check_lsp_hover.go │ │ ├── check_lsp_hover_complete_util.go │ │ ├── check_lsp_references.go │ │ ├── check_lsp_signaturehelp.go │ │ ├── check_lsp_symbol.go │ │ ├── check_second_project.go │ │ ├── check_third_file.go │ │ ├── check_util.go │ │ ├── common │ │ │ ├── annotate_enum.go │ │ │ ├── annotate_info.go │ │ │ ├── cache_lru.go │ │ │ ├── complete_cache.go │ │ │ ├── dir_manager.go │ │ │ ├── enum_info.go │ │ │ ├── err_info.go │ │ │ ├── file_index_info.go │ │ │ ├── func_info.go │ │ │ ├── global_conf.go │ │ │ ├── lsp_common.go │ │ │ ├── refer_info.go │ │ │ ├── scope_info.go │ │ │ ├── system_tips.go │ │ │ ├── util.go │ │ │ └── var_info.go │ │ ├── compiler │ │ │ ├── ast │ │ │ │ ├── attr.go │ │ │ │ ├── block.go │ │ │ │ ├── exp.go │ │ │ │ └── stat.go │ │ │ ├── lexer │ │ │ │ ├── common.go │ │ │ │ ├── lexer.go │ │ │ │ ├── lexer_test.go │ │ │ │ └── token.go │ │ │ └── parser │ │ │ │ ├── parse_block.go │ │ │ │ ├── parse_exp.go │ │ │ │ ├── parse_prefix_exp.go │ │ │ │ ├── parse_stat.go │ │ │ │ ├── parser.go │ │ │ │ ├── parser_number.go │ │ │ │ └── parser_test.go │ │ ├── projects │ │ │ └── projects.go │ │ └── results │ │ │ ├── color_result.go │ │ │ ├── file_result.go │ │ │ ├── file_struct.go │ │ │ ├── reference_result.go │ │ │ ├── single_project_result.go │ │ │ └── third_result.go │ ├── codingconv │ │ ├── codingconv.go │ │ └── condingconv_test.go │ ├── diagnostics_manager.go │ ├── filefolder │ │ └── filefolder.go │ ├── get_online_req.go │ ├── initialize.go │ ├── log │ │ └── log.go │ ├── lsp_cmd_run.go │ ├── lsp_server.go │ ├── lspcommon │ │ ├── file_cache.go │ │ └── util.go │ ├── lsptest.go │ ├── online_report.go │ ├── other_request.go │ ├── pathpre │ │ └── pathpre.go │ ├── progress_ntf.go │ ├── protocol │ │ └── tsprotocol.go │ ├── push_client_message.go │ ├── strbytesconv │ │ ├── strbytesconv.go │ │ └── strbytesconv_test.go │ ├── stringutil │ │ └── util.go │ ├── textdocument_complete.go │ ├── textdocument_complete_test.go │ ├── textdocument_define.go │ ├── textdocument_define_test.go │ ├── textdocument_file_request.go │ ├── textdocument_file_request_test.go │ ├── textdocument_highlight.go │ ├── textdocument_hover.go │ ├── textdocument_hover_test.go │ ├── textdocument_references.go │ ├── textdocument_rename.go │ ├── textdocument_signaturehelp.go │ ├── textdocument_symbol.go │ ├── textdocument_varColor.go │ ├── workspace_folders.go │ └── workspace_symbol.go ├── mac.sh ├── mac_arm64_mv.sh ├── main.go ├── mv.sh └── testdata │ ├── complete │ ├── intelligent3 │ │ └── test_intelligent3.lua │ ├── test1.lua │ ├── test10.lua │ ├── test2.lua │ ├── test3.lua │ ├── test3_require.lua │ ├── test3_require2.lua │ ├── test4.lua │ ├── test5.lua │ ├── test6.lua │ ├── test7.lua │ ├── test8.lua │ ├── test9.lua │ ├── test_alias1.lua │ ├── test_intelligent1.lua │ ├── test_intelligent2.lua │ └── test_table_key.lua │ ├── define │ ├── be_define.lua │ ├── definefolder │ │ └── init.lua │ ├── test1.lua │ ├── test2.lua │ ├── test3.lua │ ├── test4.lua │ └── test5.lua │ ├── hover │ ├── hover1.lua │ ├── hover10.lua │ ├── hover11.lua │ ├── hover2.lua │ ├── hover2_requrie.lua │ ├── hover2_requrie2.lua │ ├── hover3.lua │ ├── hover4.lua │ ├── hover4_import.lua │ ├── hover5.lua │ ├── hover6.lua │ ├── hover7.lua │ ├── hover8.lua │ ├── hover9.lua │ ├── hover_expand_g.lua │ ├── hover_expand_local.lua │ ├── hover_expand_no.lua │ └── hover_func_return.lua │ ├── parse │ ├── test1.lua │ └── test2.lua │ └── project │ ├── globalVar │ ├── one.lua │ ├── three.lua │ ├── two.lua │ └── two1.lua │ └── test1 │ └── test1.lua └── luahelper-vscode ├── .gitignore ├── .travis.yml ├── .vscode ├── extensions.json ├── launch.json ├── settings.json └── tasks.json ├── .vscodeignore ├── CHANGELOG.md ├── README.md ├── appveyor.yml ├── build ├── config.js ├── prepare-version.js └── prepare.js ├── client └── 3rd │ └── vscode-lua-doc │ ├── doc │ └── en-us │ │ └── 54 │ │ ├── contents.html │ │ ├── index.css │ │ ├── logo.gif │ │ ├── lua.css │ │ ├── manual.css │ │ ├── manual.html │ │ ├── osi-certified-72x60.png │ │ └── readme.html │ └── extension.js ├── debugger ├── LuaPanda.lua ├── debugger_lib │ ├── libpdebug.cpp │ ├── libpdebug.h │ └── plugins │ │ ├── mac │ │ └── x86_64 │ │ │ ├── 501 │ │ │ └── libpdebug.so │ │ │ └── 503 │ │ │ └── libpdebug.so │ │ └── win │ │ ├── x86 │ │ ├── 501 │ │ │ └── libpdebug.dll │ │ └── 503 │ │ │ └── libpdebug.dll │ │ └── x86_64 │ │ ├── 501 │ │ └── libpdebug.dll │ │ └── 503 │ │ └── libpdebug.dll └── luasocket │ ├── linux │ ├── lua5.1 │ │ ├── lua │ │ ├── mime │ │ │ └── core.so │ │ └── socket │ │ │ └── core.so │ ├── lua5.2 │ │ ├── lua │ │ ├── mime │ │ │ └── core.so │ │ └── socket │ │ │ └── core.so │ ├── lua5.3 │ │ ├── lua │ │ ├── mime │ │ │ └── core.so │ │ └── socket │ │ │ └── core.so │ └── lua5.4 │ │ ├── lua │ │ ├── mime │ │ └── core.so │ │ └── socket │ │ └── core.so │ ├── mac │ ├── lua5.1 │ │ ├── lua │ │ ├── mime │ │ │ └── core.so │ │ └── socket │ │ │ └── core.so │ ├── lua5.2 │ │ ├── lua │ │ ├── mime │ │ │ └── core.so │ │ └── socket │ │ │ └── core.so │ ├── lua5.3 │ │ ├── lua │ │ ├── mime │ │ │ └── core.so │ │ └── socket │ │ │ └── core.so │ └── lua5.4 │ │ ├── lua │ │ ├── mime │ │ └── core.so │ │ └── socket │ │ └── core.so │ ├── readme.md │ └── win │ ├── x64 │ ├── lua5.1 │ │ ├── lua5.1.dll │ │ ├── lua51.exe │ │ ├── mime │ │ │ └── core.dll │ │ └── socket │ │ │ └── core.dll │ ├── lua5.2 │ │ ├── lua52.dll │ │ ├── lua52.exe │ │ ├── mime │ │ │ └── core.dll │ │ └── socket │ │ │ └── core.dll │ ├── lua5.3 │ │ ├── lua53.dll │ │ ├── lua53.exe │ │ ├── mime │ │ │ └── core.dll │ │ └── socket │ │ │ └── core.dll │ └── lua5.4 │ │ ├── lua54.dll │ │ ├── lua54.exe │ │ ├── mime │ │ └── core.dll │ │ └── socket │ │ └── core.dll │ └── x86 │ ├── lua5.1 │ ├── mime │ │ └── core.dll │ └── socket │ │ └── core.dll │ ├── lua5.2 │ ├── mime │ │ └── core.dll │ └── socket │ │ └── core.dll │ ├── lua5.3 │ ├── mime │ │ └── core.dll │ └── socket │ │ └── core.dll │ └── lua5.4 │ ├── mime │ └── core.dll │ └── socket │ └── core.dll ├── images └── luahelper.png ├── language-configuration.json ├── package.json ├── package.nls.json ├── package.nls.zh-cn.json ├── server ├── armmaclualsp ├── darwin │ └── lua-format ├── linux │ └── lua-format ├── linuxlualsp ├── luafmt.config ├── lualsp.exe ├── maclualsp ├── meta │ └── template │ │ ├── basic.lua │ │ ├── bit.lua │ │ ├── bit32.lua │ │ ├── builtin.lua │ │ ├── coroutine.lua │ │ ├── debug.lua │ │ ├── ffi.lua │ │ ├── io.lua │ │ ├── jit.lua │ │ ├── math.lua │ │ ├── openrestylib.lua │ │ ├── os.lua │ │ ├── package.lua │ │ ├── string.lua │ │ ├── table.lua │ │ └── utf8.lua └── win32 │ └── lua-format.exe ├── snippets └── snippets.json ├── src ├── annotator.ts ├── common │ ├── logManager.ts │ ├── luaPath.ts │ ├── pathManager.ts │ ├── threadManager.ts │ └── tools.ts ├── debug │ ├── breakPoint.ts │ ├── dataProcessor.ts │ ├── debugAdapter.ts │ ├── luaDebug.ts │ ├── luaDebugRuntime.ts │ ├── updateManager.ts │ └── visualSetting.ts ├── extension.ts ├── languageConfiguration.ts ├── luaformat.ts ├── luapandaDebug.ts ├── notifications.ts └── onlinePeople.ts ├── syntaxes └── lua.json ├── tsconfig.json ├── tslint.json └── vsc-extension-quickstart.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/.DS_Store -------------------------------------------------------------------------------- /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | name: Go 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v2 15 | 16 | - name: Set up Go 17 | uses: actions/setup-go@v2 18 | with: 19 | go-version: 1.17 20 | 21 | - name: Build 22 | run: cd luahelper-lsp && go build -v ./... 23 | 24 | - name: Test 25 | run: cd luahelper-lsp && go test -v ./... 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | luahelper-lsp/log.txt 2 | luahelper-vscode/log.txt 3 | luahelper-lsp/luahelper-lsp.exe 4 | luahelper-lsp/__debug_bin.exe 5 | luahelper-lsp/.idea/luahelper-lsp.iml 6 | luahelper-lsp/.idea/modules.xml 7 | luahelper-lsp/.idea/vcs.xml 8 | luahelper-lsp/__debug_bin 9 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## 0.1.10 (July 9, 2020) 4 | + 完善了局部变量定义了,未使用的告警 5 | + 修复了关键字not没有着色的问题 6 | 7 | ## 0.1.8 (July 8, 2020) 8 | + 集成了LuaPanda的调试组件 9 | + 新增了or表达式永远为true的告警 10 | + 新增了and表达式永远为false的告警 11 | + 开启了局部变量定义了未使用的告警 12 | + 增强了查找定义的实现 13 | + 修复了部分用户反馈的bug 14 | 15 | ## 0.1.6 (June 12, 2020) 16 | + 变量的定义能递归跟踪到引用的其他变量 17 | + 查找引用功能增强了 18 | + 代码补全增强了功能,且修复了一个小bug 19 | 20 | ## 0.1.4 (June 2, 2020) 21 | + 修复了一些小bug 22 | 23 | ## 0.1.3 (June 2, 2020) 24 | + 没有项目配置文件时,增加默认的检查项 25 | 26 | ## 0.1.2 (May 29, 2020) 27 | 28 | + 增加require引用一个文件,查找定义 29 | + 增加require引用一个文件,查找引用 30 | + 增加require引用一个文件,代码智能提示 31 | 32 | ## 0.1.1 (May 27, 2020) 33 | 34 | + 完善了文档 35 | + 修复了全局变量着色的bug 36 | 37 | 38 | ## 0.1.0 (May 22, 2020) 39 | 40 | + 实现了代码编辑辅助等功能 41 | + 实现了工程级代码检查功能 -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 大家有任何需求都可以与我们直接沟通,或是项目组需要定制化的功能也可以及时提交给我们。 -------------------------------------------------------------------------------- /docs/images/CodeCompletion.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/CodeCompletion.gif -------------------------------------------------------------------------------- /docs/images/DocmentSymbol.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/DocmentSymbol.gif -------------------------------------------------------------------------------- /docs/images/FindReferences.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/FindReferences.gif -------------------------------------------------------------------------------- /docs/images/Format.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/Format.gif -------------------------------------------------------------------------------- /docs/images/GlobalColor.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/GlobalColor.gif -------------------------------------------------------------------------------- /docs/images/GotoDefinition.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/GotoDefinition.gif -------------------------------------------------------------------------------- /docs/images/Hover.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/Hover.gif -------------------------------------------------------------------------------- /docs/images/Install.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/Install.gif -------------------------------------------------------------------------------- /docs/images/Install1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/Install1.gif -------------------------------------------------------------------------------- /docs/images/Lsp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/Lsp.png -------------------------------------------------------------------------------- /docs/images/Lsp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/Lsp1.png -------------------------------------------------------------------------------- /docs/images/Nolsp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/Nolsp.png -------------------------------------------------------------------------------- /docs/images/Nolsp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/Nolsp1.png -------------------------------------------------------------------------------- /docs/images/Proxys.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/Proxys.gif -------------------------------------------------------------------------------- /docs/images/RealTimeCheck.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/RealTimeCheck.gif -------------------------------------------------------------------------------- /docs/images/SemanticCheck.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/SemanticCheck.gif -------------------------------------------------------------------------------- /docs/images/SyntaxCheck.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/SyntaxCheck.gif -------------------------------------------------------------------------------- /docs/images/WorkspaceSymbol.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/WorkspaceSymbol.gif -------------------------------------------------------------------------------- /docs/images/annotate/array_test1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/annotate/array_test1.png -------------------------------------------------------------------------------- /docs/images/annotate/array_test2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/annotate/array_test2.png -------------------------------------------------------------------------------- /docs/images/annotate/class_test1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/annotate/class_test1.png -------------------------------------------------------------------------------- /docs/images/annotate/class_test2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/annotate/class_test2.png -------------------------------------------------------------------------------- /docs/images/annotate/generic_test1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/annotate/generic_test1.png -------------------------------------------------------------------------------- /docs/images/annotate/param_test1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/annotate/param_test1.png -------------------------------------------------------------------------------- /docs/images/annotate/return_test1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/annotate/return_test1.png -------------------------------------------------------------------------------- /docs/images/annotate/sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/annotate/sample.png -------------------------------------------------------------------------------- /docs/images/annotate/table_test1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/annotate/table_test1.png -------------------------------------------------------------------------------- /docs/images/clientexe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/clientexe.png -------------------------------------------------------------------------------- /docs/images/debug/addconfiguration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/debug/addconfiguration.png -------------------------------------------------------------------------------- /docs/images/debug/begindebug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/debug/begindebug.png -------------------------------------------------------------------------------- /docs/images/debug/debugattach.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/debug/debugattach.png -------------------------------------------------------------------------------- /docs/images/debug/debugfile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/debug/debugfile.png -------------------------------------------------------------------------------- /docs/images/debug/debugfilerun.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/debug/debugfilerun.png -------------------------------------------------------------------------------- /docs/images/debug/debugprinciple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/debug/debugprinciple.png -------------------------------------------------------------------------------- /docs/images/debug/debugsetting.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/debug/debugsetting.gif -------------------------------------------------------------------------------- /docs/images/debug/debugstruct.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/debug/debugstruct.png -------------------------------------------------------------------------------- /docs/images/debug/debugsuffix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/debug/debugsuffix.png -------------------------------------------------------------------------------- /docs/images/debug/debugways.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/debug/debugways.png -------------------------------------------------------------------------------- /docs/images/debug/go.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/debug/go.png -------------------------------------------------------------------------------- /docs/images/debug/launch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/debug/launch.png -------------------------------------------------------------------------------- /docs/images/debug/runonefile.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/debug/runonefile.gif -------------------------------------------------------------------------------- /docs/images/debug/shortcutcmd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/debug/shortcutcmd.png -------------------------------------------------------------------------------- /docs/images/debug/socket.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/debug/socket.png -------------------------------------------------------------------------------- /docs/images/exe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/exe.png -------------------------------------------------------------------------------- /docs/images/go.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/go.png -------------------------------------------------------------------------------- /docs/images/install.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/install.png -------------------------------------------------------------------------------- /docs/images/json.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/json.png -------------------------------------------------------------------------------- /docs/images/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/logo.jpg -------------------------------------------------------------------------------- /docs/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/logo.png -------------------------------------------------------------------------------- /docs/images/logo_single.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/logo_single.png -------------------------------------------------------------------------------- /docs/images/lsp2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/lsp2.png -------------------------------------------------------------------------------- /docs/images/running.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/running.png -------------------------------------------------------------------------------- /docs/images/socket.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/socket.png -------------------------------------------------------------------------------- /docs/images/src.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/images/src.png -------------------------------------------------------------------------------- /docs/jsonconfig/client/luahelper.json: -------------------------------------------------------------------------------- 1 | { 2 | "BaseDir":"./bin/", 3 | "ShowWarnFlag": 1, 4 | "ShareSymbolsFlag": 1, 5 | "ReferMatchPathFlag": 0, 6 | "GvalTipFlag": 1, 7 | "IgnoreFileNameVarFlag": 1, 8 | "ProjectFiles":[], 9 | "IgnoreModules":["hive", "import"], 10 | "IgnoreFileVars": [ 11 | { 12 | "File": "lobby/gm.lua", 13 | "Vars": ["ss"] 14 | }, 15 | { 16 | "File": "gamesvr/game_mgr.lua", 17 | "Vars": ["fake_load"] 18 | } 19 | ], 20 | "IgnoreReadFiles": [ 21 | "config/dbagent.lua", 22 | "config/lobby.lua" 23 | ], 24 | "IgnoreErrorTypes": [ 25 | ], 26 | "IgnoreFileOrFloder": [ 27 | "lobby/on.*lua", 28 | "tests/", 29 | "robot/", 30 | "coverage/" 31 | ], 32 | "IgnoreFileErr": [ 33 | "lobby/gm1.lua", 34 | "common/test.lua" 35 | ], 36 | "IgnoreFileErrTypes": [ 37 | { 38 | "File": "lobby/gm.lua", 39 | "Types": [11] 40 | } 41 | ], 42 | "ProtocolVars": [] 43 | } -------------------------------------------------------------------------------- /docs/jsonconfig/luahelper.json: -------------------------------------------------------------------------------- 1 | { 2 | "BaseDir":"./", 3 | "ShowWarnFlag": 1, 4 | "ShareSymbolsFlag": 1, 5 | "ReferMatchPathFlag": 0, 6 | "GvalTipFlag": 1, 7 | "IgnoreFileNameVarFlag": 0, 8 | "ProjectFiles":[], 9 | "IgnoreModules":["hive", "import"], 10 | "IgnoreFileVars": [ 11 | { 12 | "File": "port/gm.lua", 13 | "Vars": ["bb", "cc"] 14 | }, 15 | { 16 | "File": "port/ss.lua", 17 | "Vars": ["aa", "dd"] 18 | } 19 | ], 20 | "IgnoreReadFiles": [ 21 | "config/port.lua", 22 | "config/act.lua" 23 | ], 24 | "IgnoreErrorTypes": [4], 25 | "IgnoreFileOrFloder": [ 26 | "port/on.*lua", 27 | "tests/", 28 | "one.lua" 29 | ], 30 | "IgnoreFileErr": [ 31 | "port/add.lua", 32 | "common/test.lua" 33 | ], 34 | "IgnoreFileErrTypes": [ 35 | { 36 | "File": "port/bbb.lua", 37 | "Types": [4] 38 | }, 39 | { 40 | "File": "port/ss.lua", 41 | "Types": [4, 5] 42 | } 43 | ], 44 | "ProtocolVars": [] 45 | } -------------------------------------------------------------------------------- /docs/manual/FAQ.html: -------------------------------------------------------------------------------- 1 |

##FAQ

2 | -------------------------------------------------------------------------------- /docs/manual/FAQ.md: -------------------------------------------------------------------------------- 1 | #FAQ -------------------------------------------------------------------------------- /docs/manual/FAQ.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/manual/FAQ.pdf -------------------------------------------------------------------------------- /docs/manual/Feature.md: -------------------------------------------------------------------------------- 1 | ## Feature Summary 2 | 3 | ### Code Editing 4 | * [Defintion Find [定义跳转]](#DefintionFind "定义跳转") 5 | * [Find All References [引用查找]](#FindAllReferences "引用查找") 6 | * [Document Symbols [文件符号表查询]](#DocumentSymbols "文件符号表查询") 7 | * [Workspace Symbols [工程符号表查询]](#WorkspaceSymbols "工程符号表查询") 8 | * [Auto Code Completion [自动代码补全]](#AutoCodeCompletion "自动代码补全") 9 | * [Format Code [代码格式化]](#FormatCode "代码格式化") 10 | * [Hover [代码悬停]](#Hover "代码悬停") 11 | * [Hightlight Global Var [全局变量着色]](#HightlightGlobalVar "全局变量着色") 12 | 13 | ### Code Detection 14 | * [Syntax Check [语法检测]](#SyntaxCheck "语法检测") 15 | * [Semantic Check [语义检测]](#SemanticCheck "语义检测") 16 | * [Quick Analysis [快速增量分析]](#QuickAnalysis "快速增量分析") 17 | 18 | ## Feature Detail 19 | ### Defintion Find/定义跳转 20 | **支持局部、全局文件定义查询跳转** 21 | ![avatar](https://raw.githubusercontent.com/Tencent/LuaHelper/master/images/GotoDefinition.gif) 22 | 23 | ### Find All References/引用查找 24 | **支持基于作用域的各类型引用查找** 25 | ![avatar](https://raw.githubusercontent.com/Tencent/LuaHelper/master/images/FindReferences.gif) 26 | 27 | ### Document Symbols/文件符号表查询 28 | **支持文件域符号表查询,在搜索栏输入@** 29 | ![avatar](https://raw.githubusercontent.com/Tencent/LuaHelper/master/images/DocmentSymbol.gif) 30 | 31 | ### Workspace Symbols/工程符号表查询 32 | **支持工程域符号表查询,在搜索栏输入#** 33 | ![avatar](https://raw.githubusercontent.com/Tencent/LuaHelper/master/images/WorkspaceSymbol.gif) 34 | 35 | ### Auto Code Completion/自动代码补全 36 | **支持变量、函数的自动输入提示** 37 | ![avatar](https://raw.githubusercontent.com/Tencent/LuaHelper/master/images/CodeCompletion.gif) 38 | 39 | ### Format Code/代码格式化 40 | **支持代码格式化** 41 | 42 | ![avatar](https://raw.githubusercontent.com/Tencent/LuaHelper/master/images/Format.gif) 43 | 44 | ### Hover/代码悬停 45 | **支持代码悬停提示** 46 | 47 | ![avatar](https://raw.githubusercontent.com/Tencent/LuaHelper/master/images/Hover.gif) 48 | 49 | ### Hightlight Global Var/全局变量着色 50 | **支持全局变量高亮着色** 51 | ![avatar](https://raw.githubusercontent.com/Tencent/LuaHelper/master/images/GlobalColor.gif) 52 | 53 | ### Syntax Check/语法检测 54 | **提供丰富的语法错误检测类型** 55 | ![avatar](https://raw.githubusercontent.com/Tencent/LuaHelper/master/images/SyntaxCheck.gif) 56 | 57 | ### Semantic Check/语义检测 58 | **支持多种类型的语义检测** 59 | ![avatar](https://raw.githubusercontent.com/Tencent/LuaHelper/master/images/SemanticCheck.gif) 60 | 61 | ### Quick Analysis/快速增量分析 62 | **支持增量变化分析,分析结果诊断输出** 63 | ![avatar](https://raw.githubusercontent.com/Tencent/LuaHelper/master/images/RealTimeCheck.gif) 64 | 65 | -------------------------------------------------------------------------------- /docs/manual/annotate.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/manual/annotate.pdf -------------------------------------------------------------------------------- /docs/manual/debugPrinciple.md: -------------------------------------------------------------------------------- 1 | # 调试器原理 2 | 3 | ## 调试器协议 4 | 调试器的实现采用了微软推出的[Debug Adapter Protocol](https://microsoft.github.io/debug-adapter-protocol/),它把开发工具(IDE或Iditor)与不同语言的debugger功能解耦, 并把两者之间的通信的方式抽象为通用协议(JSON格式)。通过调试适配器协议,可以为开发工具实现通用调试器,该调试器可以通过调试适配器与不同的调试器进行通信。调试适配器可以在多个开发工具中重复使用,从而大大减少了在不同工具中支持新调试器的工作。 5 | 6 | ![avatar](https://raw.githubusercontent.com/Tencent/LuaHelper/master/images/debug/debugprinciple.png) 7 | 8 | 9 | 调试的过程涉及了三个角色: 10 | * 开发工具(IDE、Editor)。 11 | * 调试适配器协议(Debug Adapter Protocol),中间沟通作用。协议采用JSON格式,通用性较强。 12 | * 后端调试器(Debugger),负责调试主体功能的实现。 13 | 14 | 调试适配器初始化之后,就可以接受启动调试的请求。请求主要分为两类: 15 | 16 | * launch请求:调试适配器以调试模式启动程序,然后开始与其通信。 17 | * attach请求:调试适配器连接到已经运行的程序。 最终用户在这里负责启动和终止程序。 18 | 19 | ## 实现架构 20 | LuaPanda调试的架构采用了attach请求模式,attach的作用是附加到运行Lua代码的可执行程序上,调试器前端VSCode工程与运行的lua进程(被调试的进程)通过socket通信。下图是LuaHelper集成了LuaPanda调试模块后的调试架构图。 21 | 22 | ![avatar](https://raw.githubusercontent.com/Tencent/LuaHelper/master/images/debug/debugstruct.png) 23 | 24 | 整个调试功能分为两大主体: 25 | * VSCode打开的Lua工程:上图中左边框。 26 | * 运行Lua工程的进程:上图中左边框。 27 | 28 | 整个调试的流程如下: 29 | * 1)打开Lua工程,激活LuaHelper插件。 30 | * 2)Lua工程中主动引入LuaPanda.lua文件,引入的代码片段为: 31 | ```lua 32 | require("LuaPanda").start("127.0.0.1", 8818); 33 | ``` 34 | * 3)VSCode打开的Lua工程,F5主动开启调试功能,监听socket连接。 35 | * 4)主动执行Lua工程,当代码中运行到引入的LuaPanda.lua文件时,会主动socket链接前端调试的工程。 36 | * 5)运行Lua工程的进程与前端调试的工程attach成功,开始调试功能。 37 | * 6)前端调试工程设置好断点,通知给运行Lua工程的进程,运行Lua工程的进程设置好hook信息。 38 | * 7)运行Lua工程的进程执行到预先设置的断点处,从lua虚拟机获取到的调试信息,发送给前端工程展示。 -------------------------------------------------------------------------------- /docs/manual/debugsinglefile.md: -------------------------------------------------------------------------------- 1 | # 单文件调试与运行 2 | ### 1背景 3 | 在做lua开发过程中,有时希望在一个独立文件中测试函数执行结果。单文件的执行/调试也是为了方便这种场景。 4 | 5 | ### 2调试配置 6 | 首先需要设置调试配置,调试配置参考前文。然后选择下图中LuaHelper-DebugFile选项 7 | ![avatar](https://raw.githubusercontent.com/Tencent/LuaHelper/master/images/debug/debugfile.png) 8 | 9 | 10 | ### 3调试单个文件 11 | 调试选项切换LuaPanda-DebugFile, 代码编辑窗口切换到待调试文件,按F5快捷键进行调试。这种模式下,不用引入LuaPanda.lua文件和luasocket库。 12 | 13 | ![avatar](https://raw.githubusercontent.com/Tencent/LuaHelper/master/images/debug/debugfilerun.png) 14 | 15 | 16 | ### 4单文件运行 17 | 调试选项切换LuaPanda-DebugFile, 代码编辑窗口切换到待运行的文件,按ctrl + F5 快捷键运行lua文件。。这种模式下,也不用引入LuaPanda.lua文件和luasocket库。 18 | 19 | ![avatar](https://raw.githubusercontent.com/Tencent/LuaHelper/master/images/debug/runonefile.gif) 20 | -------------------------------------------------------------------------------- /docs/manual/debuguse.md: -------------------------------------------------------------------------------- 1 | ## 插件调试的方法 2 | ### 1 插件前端的调试 3 | * a) 需要安装npm 4 | * b) npm安装vsce, 命令:npm install -g vsce 5 | * c) 命令行进入luahelper-vscode目录,执行npm install 6 | * d) VSCode 打开luahelper-vscode客户端目录,直接调试即可 7 | 8 | 前端调试的时候,会新创建一个VSCode终端,在对应的终端里面打开lua工程文件夹就可以调试前端。 9 | 10 | ### 2 插件后端的调试 11 | 后端是go语言写的,如果是用VSCode打开后端程序,需要打开目录:luahelper-lsp 12 | 13 | #### 2.1 VSCode安装go的插件 14 | 在插件市场搜索Go,安装排名第一的插件即可 15 | 16 | ![avatar](https://raw.githubusercontent.com/Tencent/LuaHelper/master/images/debug/go.png) 17 | 18 | #### 2.2 VSCode打开luahelper-lsp目录,按F5调试即可 19 | 20 | #### 2.3 设置插件前端连接Go后端 21 | 插件前端与插件后端协议的格式Json RPC,如下图所示 22 | ![avatar](https://raw.githubusercontent.com/Tencent/LuaHelper/master/images/running.png) 23 | 24 | 插件前端连接后端有两种方式: 25 | * a) 通过管道的方式,插件前端直接拉取后端exe程序 26 | * b) 通过socket的方式 27 | 28 | 为了使插件前端通过socket连接的后端,前端插件的设置如下: 29 | (选设置-》Lua Helper—》 Project:Lsp (勾选socket rpc) 30 | 31 | ![avatar](https://raw.githubusercontent.com/Tencent/LuaHelper/master/images/debug/socket.png) 32 | 33 | 34 | #### 2.4 VSCode重新打开Lua工程 35 | 36 | 通过socket连接上后,就可以调试go的后端程序,在go的后端就可以调试go的代码 37 | -------------------------------------------------------------------------------- /docs/manual/head.tex: -------------------------------------------------------------------------------- 1 | \usepackage{framed} 2 | \usepackage{quoting} 3 | \usepackage{xcolor} 4 | 5 | \definecolor{bgcolor}{HTML}{DADADA} 6 | 7 | \let\oldtexttt\texttt 8 | 9 | \renewcommand{\texttt}[1]{ 10 | \colorbox{bgcolor}{\oldtexttt{#1}} 11 | } 12 | 13 | \colorlet{shadecolor}{bgcolor} 14 | % define a new environment shadedquotation. You can change leftmargin and 15 | % rightmargin as you wish. 16 | \newenvironment{shadedquotation} 17 | {\begin{shaded*} 18 | \quoting[leftmargin=1em, rightmargin=0pt, vskip=0pt] 19 | } 20 | {\endquoting 21 | \end{shaded*} 22 | } 23 | 24 | % 25 | \def\quote{\shadedquotation} 26 | \def\endquote{\endshadedquotation} 27 | 28 | \usepackage{fvextra} 29 | \DefineVerbatimEnvironment{Highlighting}{Verbatim}{breaklines,commandchars=\\\{\}} -------------------------------------------------------------------------------- /docs/manual/introduction.md: -------------------------------------------------------------------------------- 1 | # 项目背景 2 | 3 | Lua是简单、易上手的脚本语言,在游戏开发中十分流行。由于是脚本语言,代码没有编译的概念,极容易编写出不规范的代码,且没有类型系统,因此在大型项目中维护比较困难。 4 | 5 | 笔者的Lua项目比较庞大,遇到了下面问题: 6 | 1. 工程中包含的Lua文件超过了1300个,部分VS Code的插件会运行卡顿,且占用资源巨大。 7 | 2. 没有专业的工程级的检查代码工具(目前存在的代码检查工具是基于单文件的),很多代码问题直到运行期间才会暴露。 8 | 3. 工程中用到了特有的import导入一个lua文件(封装了各自的环境变量),导致几乎所有插件无法跳转和代码补全。 9 | 10 | 因此,使用Go语言定制开发了一款Vs Code插件,它把代码编写与代码检查功能集合在一起,进一步提升大家的编码效率。其中代码检查功能是基于整个工程的,且检查项是可以需要配置的。 11 | 12 | [告警配置方法](./config.md) 13 | 14 | -------------------------------------------------------------------------------- /docs/manual/mainsource.md: -------------------------------------------------------------------------------- 1 | ## 源码及架构 2 | [1 源码整体介绍](./source.md "源码整体介绍") 3 | 4 | [2 源码调试](./debuguse.md "源码调试") -------------------------------------------------------------------------------- /docs/manual/source.md: -------------------------------------------------------------------------------- 1 | # 源码介绍及安装 2 | 3 | ## 1 整体介绍 4 | 微软Language Server Protocol协议,是一种被用于编辑器或集成开发环境与支持比如自动补全,定义跳转,查找所有引用等语言特性的语言服务器之间的一种协议。 5 | 6 | 7 | 早期,没有LSP协议,如果要为语言编写不同编辑器下的插件,每种编辑器下都需要单独开发。 8 | ![avatar](https://raw.githubusercontent.com/Tencent/LuaHelper/master/images/Nolsp.png) 9 | 10 | 后面,微软推出了LSP协议,把插件的开发分为前端和后端,后端可以使用其他语言,且可以适配不同的前端。那么不同编辑器下插件,可以利用同一个后端,极大的减少插件的开发量。同时,插件的后端可以采用任何语言,不局限于前端的语言。前端与后端通信,采用Json协议格式。如下图所示。 11 | ![avatar](https://raw.githubusercontent.com/Tencent/LuaHelper/master/images/Lsp.png) 12 | 13 | ## 2 源码介绍 14 | 本插件,前端是利用Typescript语言,后端是采用Go语言。 15 | 源码目录如下: 16 | ![avatar](https://raw.githubusercontent.com/Tencent/LuaHelper/master/images/src.png) 17 | 18 | luahelper-lsp目录,是后端go程序目录。
19 | luahelper-vscode目录,是前端typescript程序目录。 20 | 21 | ## 3 源码编译的方法 22 | ### 3.1 后端go程序编译方法 23 | * **a)首先把源码 ..\LuaHelper\luahelper-lsp目录添加到GoPath环境变量中** 24 | * **b)进入到 ..\LuaHelper\luahelper-lsp\bin目录,执行go编译命令:**
25 | go build -ldflags "-w -s" lualsp
26 | 如果是windows环境,会编译出lualsp.exe
27 | 如果是linux环境,会编译出lualsp, 二进制更改名称为: linuxlualsp
28 | 如果是mac环境,会编译出lualsp, 二进制更改名称为: maclualsp
29 | * **c) 把编译出来的go二进制(总共三个环境二进制),拷贝到插件前端目录中:**
30 | ..\LuaHelper\luahelper-vscode\server ,目录如下图所示: 31 | ![avatar](https://raw.githubusercontent.com/Tencent/LuaHelper/master/images/clientexe.png) 32 | * **d) 前端插件编译的时候,会把..\LuaHelper\luahelper-vscode\server目录下的二进制打包到插件中。**
33 | 插件运行时,会根据不同的平台加载相应的二进制执行。 34 | 35 | 36 | ### 3.2 前端插件的编译方法 37 | * **a) 先安装npm包管理**
38 | npm完整的安装方法:
39 | https://www.jianshu.com/p/03a76b2e7e00
40 | 查看所有的npm配置
41 | npm 设置代理,代理设置方法,在默认的配置文件中(zhangsan为windows用户名):
42 | C:\Users\zhangsan
43 | 文件:.npmrc
44 | .npmrc文件内增加下面的内容:
45 | http-proxy=http://127.0.0.1:12639
46 | https-proxy=http://127.0.0.1:12639
47 | * **b) 全局安装vsce**
48 | 安装命令为:npm install -g vsce
49 | * **c) 进来插件前端源码目录,安装相应依赖包**
50 | 目录为:..\LuaHelper\luahelper-vscode 51 | 运行命令: npm install
52 | * **d) 编译源码**
53 | 目录为:..\LuaHelper\luahelper-vscode
54 | 运行命令:vsce package
55 | 当前目录下为生成对应的vsix文件 -------------------------------------------------------------------------------- /docs/manual/usedebug.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/docs/manual/usedebug.docx -------------------------------------------------------------------------------- /docs/manual/~$edebug.docx: -------------------------------------------------------------------------------- 1 | yvanfyinyvanfyin -------------------------------------------------------------------------------- /images/CodeCompletion.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/CodeCompletion.gif -------------------------------------------------------------------------------- /images/DocmentSymbol.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/DocmentSymbol.gif -------------------------------------------------------------------------------- /images/FindReferences.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/FindReferences.gif -------------------------------------------------------------------------------- /images/Format.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/Format.gif -------------------------------------------------------------------------------- /images/GlobalColor.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/GlobalColor.gif -------------------------------------------------------------------------------- /images/GotoDefinition.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/GotoDefinition.gif -------------------------------------------------------------------------------- /images/Hover.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/Hover.gif -------------------------------------------------------------------------------- /images/Install.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/Install.gif -------------------------------------------------------------------------------- /images/Lsp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/Lsp.png -------------------------------------------------------------------------------- /images/Lsp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/Lsp1.png -------------------------------------------------------------------------------- /images/Nolsp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/Nolsp.png -------------------------------------------------------------------------------- /images/Nolsp1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/Nolsp1.png -------------------------------------------------------------------------------- /images/Proxys.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/Proxys.gif -------------------------------------------------------------------------------- /images/RealTimeCheck.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/RealTimeCheck.gif -------------------------------------------------------------------------------- /images/SemanticCheck.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/SemanticCheck.gif -------------------------------------------------------------------------------- /images/SyntaxCheck.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/SyntaxCheck.gif -------------------------------------------------------------------------------- /images/WorkspaceSymbol.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/WorkspaceSymbol.gif -------------------------------------------------------------------------------- /images/annotate/array_test1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/annotate/array_test1.png -------------------------------------------------------------------------------- /images/annotate/array_test2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/annotate/array_test2.png -------------------------------------------------------------------------------- /images/annotate/class_test1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/annotate/class_test1.png -------------------------------------------------------------------------------- /images/annotate/sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/annotate/sample.png -------------------------------------------------------------------------------- /images/annotate/table_test1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/annotate/table_test1.png -------------------------------------------------------------------------------- /images/clientexe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/clientexe.png -------------------------------------------------------------------------------- /images/debug/addconfiguration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/debug/addconfiguration.png -------------------------------------------------------------------------------- /images/debug/begindebug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/debug/begindebug.png -------------------------------------------------------------------------------- /images/debug/debugattach.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/debug/debugattach.png -------------------------------------------------------------------------------- /images/debug/debugfile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/debug/debugfile.png -------------------------------------------------------------------------------- /images/debug/debugfilerun.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/debug/debugfilerun.png -------------------------------------------------------------------------------- /images/debug/debugprinciple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/debug/debugprinciple.png -------------------------------------------------------------------------------- /images/debug/debugsetting.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/debug/debugsetting.gif -------------------------------------------------------------------------------- /images/debug/debugstruct.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/debug/debugstruct.png -------------------------------------------------------------------------------- /images/debug/debugsuffix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/debug/debugsuffix.png -------------------------------------------------------------------------------- /images/debug/debugways.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/debug/debugways.png -------------------------------------------------------------------------------- /images/debug/go.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/debug/go.png -------------------------------------------------------------------------------- /images/debug/launch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/debug/launch.png -------------------------------------------------------------------------------- /images/debug/runonefile.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/debug/runonefile.gif -------------------------------------------------------------------------------- /images/debug/shortcutcmd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/debug/shortcutcmd.png -------------------------------------------------------------------------------- /images/debug/socket.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/debug/socket.png -------------------------------------------------------------------------------- /images/exe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/exe.png -------------------------------------------------------------------------------- /images/install.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/install.png -------------------------------------------------------------------------------- /images/json.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/json.png -------------------------------------------------------------------------------- /images/lsp2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/lsp2.png -------------------------------------------------------------------------------- /images/running.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/running.png -------------------------------------------------------------------------------- /images/src.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/images/src.png -------------------------------------------------------------------------------- /luahelper-lsp/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /luahelper-lsp/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Launch", 9 | "type": "go", 10 | "request": "launch", 11 | "mode": "auto", 12 | //"program": "${fileDirname}", 13 | "program": "${workspaceFolder}/main.go", 14 | "env": {}, 15 | "args": ["-mode=2", "-logflag=1"] 16 | }, 17 | { 18 | "type": "node", 19 | "request": "attach", 20 | "name": "Attach to Server", 21 | "port": 7771, 22 | "restart": true, 23 | "outFiles": ["${workspaceRoot}/main.go"] 24 | }, 25 | ] 26 | } -------------------------------------------------------------------------------- /luahelper-lsp/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "go.inferGopath": false 3 | } -------------------------------------------------------------------------------- /luahelper-lsp/build_mac_arm64.sh: -------------------------------------------------------------------------------- 1 | GOOS=darwin GOARCH=arm64 go build 2 | -------------------------------------------------------------------------------- /luahelper-lsp/go.mod: -------------------------------------------------------------------------------- 1 | module luahelper-lsp 2 | 3 | go 1.15 4 | 5 | require ( 6 | github.com/yinfei8/jrpc2 v0.13.1 7 | golang.org/x/text v0.3.5 8 | ) 9 | -------------------------------------------------------------------------------- /luahelper-lsp/go.sum: -------------------------------------------------------------------------------- 1 | github.com/google/go-cmp v0.5.1 h1:JFrFEBb2xKufg6XkJsJr+WbKb4FQlURi5RUcBveYu9k= 2 | github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 3 | github.com/yinfei8/jrpc2 v0.13.1 h1:SO+eXyzSByidR8dA9x2OqKa/GyPKT6vVeNnOSYKqkOQ= 4 | github.com/yinfei8/jrpc2 v0.13.1/go.mod h1:DxdSQ5smjJIzyzUWhh8maSff5nkyz8sW+MseIElTkTY= 5 | golang.org/x/sync v0.0.0-20201207232520-09787c993a3a h1:DcqTD9SDLc+1P/r1EmRBwnVsrOwW+kk2vWf9n+1sGhs= 6 | golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 7 | golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ= 8 | golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 9 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 10 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 11 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= 12 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 13 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/analysis/analysis_block.go: -------------------------------------------------------------------------------- 1 | package analysis 2 | 3 | import ( 4 | "luahelper-lsp/langserver/check/common" 5 | "luahelper-lsp/langserver/check/compiler/ast" 6 | ) 7 | 8 | func (a *Analysis) cgBlock(node *ast.Block) { 9 | for _, stat := range node.Stats { 10 | a.cgStat(stat) 11 | } 12 | 13 | if node.RetExps != nil { 14 | a.cgRetStat(node.RetExps) 15 | } 16 | } 17 | 18 | func (a *Analysis) cgRetStat(exps []ast.Exp) { 19 | nExps := len(exps) 20 | if nExps == 0 { 21 | return 22 | } 23 | 24 | returnInfo := &common.ReturnInfo{} 25 | for _, exp := range exps { 26 | a.cgExp(exp, nil, nil) 27 | 28 | // 只在第一轮中才进行存储返回值 29 | // if !a.isFirstTerm() { 30 | // continue 31 | // } 32 | 33 | returnItem := common.ReturnItem{} 34 | returnItem.VarType = common.GetExpType(exp) 35 | returnItem.VarInfo = a.getExpReferVarInfo(exp) 36 | returnItem.ReturnExp = exp 37 | 38 | returnInfo.ReturnVarVec = append(returnInfo.ReturnVarVec, returnItem) 39 | 40 | a.funcReturnCheck(returnInfo) 41 | } 42 | 43 | fi := a.curFunc 44 | if a.isFirstTerm() { 45 | fi.InsertReturn(returnInfo) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/analysis/analysis_check_assign.go: -------------------------------------------------------------------------------- 1 | package analysis 2 | 3 | import ( 4 | "fmt" 5 | "luahelper-lsp/langserver/check/common" 6 | "luahelper-lsp/langserver/check/compiler/ast" 7 | "strings" 8 | ) 9 | 10 | // 判断复制表达式是否改变了类型 11 | func (a *Analysis) checkAssignTypeSame(leftNode ast.Exp, rightNode ast.Exp) { 12 | if !a.isNeedCheck() || a.realTimeFlag { 13 | return 14 | } 15 | 16 | if common.GConfig.IsGlobalIgnoreErrType(common.CheckErrorAssignType) { 17 | return 18 | } 19 | 20 | if _, ok := common.GConfig.OpenErrorTypeMap[common.CheckErrorAssignType]; !ok { 21 | return 22 | } 23 | 24 | //当左值是表成员时,不判断,如a.b, a["b"] 25 | if _, ok := leftNode.(*ast.TableAccessExp); ok { 26 | return 27 | } 28 | if _, ok := rightNode.(*ast.TableAccessExp); ok { 29 | return 30 | } 31 | 32 | leftTypeVec := a.GetAnnTypeByExp(leftNode, -1) 33 | if len(leftTypeVec) == 0 { 34 | return 35 | } 36 | 37 | rightTypeVec := a.GetAnnTypeByExp(rightNode, -1) 38 | if len(rightTypeVec) == 0 { 39 | return 40 | } 41 | 42 | hasMatch := false 43 | for _, leftType := range leftTypeVec { 44 | for _, rightType := range rightTypeVec { 45 | if a.CompAnnTypeForAssign(rightType, leftType) { 46 | hasMatch = true 47 | break 48 | } 49 | } 50 | } 51 | 52 | if !hasMatch { 53 | loc := common.GetExpLoc(leftNode) 54 | leftTypeVecStr := strings.Join(leftTypeVec, "|") 55 | rightTypeStr := strings.Join(rightTypeVec, "|") 56 | 57 | errStr := fmt.Sprintf("Type '%s' can not be assigned '%s'", leftTypeVecStr, rightTypeStr) 58 | a.curResult.InsertError(common.CheckErrorAssignType, errStr, loc) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/analysis/analysis_check_binop.go: -------------------------------------------------------------------------------- 1 | package analysis 2 | 3 | import ( 4 | "fmt" 5 | "luahelper-lsp/langserver/check/common" 6 | "luahelper-lsp/langserver/check/compiler/ast" 7 | "luahelper-lsp/langserver/check/compiler/lexer" 8 | "strings" 9 | ) 10 | 11 | func (a *Analysis) checkBinopExpTypeSame(node *ast.BinopExp) { 12 | if !a.isNeedCheck() || a.realTimeFlag { 13 | return 14 | } 15 | 16 | if common.GConfig.IsGlobalIgnoreErrType(common.CheckErrorBinopType) { 17 | return 18 | } 19 | 20 | if _, ok := common.GConfig.OpenErrorTypeMap[common.CheckErrorBinopType]; !ok { 21 | return 22 | } 23 | 24 | if node.Op == lexer.TkOpMinus || 25 | node.Op == lexer.TkOpAdd || 26 | node.Op == lexer.TkOpMul || 27 | node.Op == lexer.TkOpDiv { 28 | //go on 29 | } else { 30 | return 31 | } 32 | 33 | leftNode := node.Exp1 34 | rightNode := node.Exp2 35 | 36 | //当是表成员时,不判断,如a.b, a["b"] 37 | if _, ok := leftNode.(*ast.TableAccessExp); ok { 38 | return 39 | } 40 | if _, ok := rightNode.(*ast.TableAccessExp); ok { 41 | return 42 | } 43 | 44 | leftTypeVec := a.GetAnnTypeByExp(leftNode, -1) 45 | if len(leftTypeVec) == 0 { 46 | return 47 | } 48 | 49 | rightTypeVec := a.GetAnnTypeByExp(rightNode, -1) 50 | if len(rightTypeVec) == 0 { 51 | return 52 | } 53 | 54 | hasMatch := false 55 | for _, leftType := range leftTypeVec { 56 | for _, rightType := range rightTypeVec { 57 | if a.CompAnnTypeForBinop(rightType, leftType) { 58 | hasMatch = true 59 | break 60 | } 61 | } 62 | } 63 | 64 | if !hasMatch { 65 | loc := common.GetExpLoc(node) 66 | leftTypeVecStr := strings.Join(leftTypeVec, "|") 67 | rightTypeStr := strings.Join(rightTypeVec, "|") 68 | 69 | errStr := fmt.Sprintf("Binary expression has different type, '%s' with '%s'", leftTypeVecStr, rightTypeStr) 70 | a.curResult.InsertError(common.CheckErrorBinopType, errStr, loc) 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/analysis/analysis_check_const.go: -------------------------------------------------------------------------------- 1 | package analysis 2 | 3 | import ( 4 | "fmt" 5 | "luahelper-lsp/langserver/check/common" 6 | "luahelper-lsp/langserver/check/compiler/ast" 7 | "luahelper-lsp/langserver/check/compiler/lexer" 8 | ) 9 | 10 | // 是否给常量赋值 当有a.b.c时,只判断a是否常量 若a是import值,则只判断b是否常量 11 | func (a *Analysis) checkConstAssgin(node ast.Exp) { 12 | if !a.isNeedCheck() || a.realTimeFlag { 13 | return 14 | } 15 | 16 | if common.GConfig.IsGlobalIgnoreErrType(common.CheckErrorConstAssign) { 17 | return 18 | } 19 | 20 | if _, ok := common.GConfig.OpenErrorTypeMap[common.CheckErrorConstAssign]; !ok { 21 | return 22 | } 23 | 24 | preName := "" 25 | varName := "" 26 | preLoc := lexer.Location{} 27 | varLoc := lexer.Location{} 28 | switch exp := node.(type) { 29 | case *ast.NameExp: 30 | varName = exp.Name 31 | varLoc = exp.Loc 32 | case *ast.TableAccessExp: 33 | preName, varName, _, preLoc, varLoc, _ = common.GetTableNameInfo(exp) 34 | } 35 | 36 | ok, varInfo, isPreImport, _ := a.findVarDefineWithPre(preName, varName, preLoc, varLoc, false) 37 | if !ok { 38 | return 39 | } 40 | if varInfo.Loc == varLoc { 41 | //定义处不检查 42 | return 43 | } 44 | if varInfo.ReferInfo != nil { 45 | //引用不检查 46 | return 47 | } 48 | 49 | if a.Projects.IsAnnotateTypeConst(varName, varInfo) { 50 | tabName := preName 51 | if isPreImport || tabName == "" { 52 | tabName = varName 53 | } 54 | 55 | //标记了常量,却赋值 56 | errStr := fmt.Sprintf("'%s' is constant and not assignable", varName) 57 | a.curResult.InsertError(common.CheckErrorConstAssign, errStr, varLoc) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/analysis/analysis_check_enum.go: -------------------------------------------------------------------------------- 1 | package analysis 2 | 3 | import ( 4 | "fmt" 5 | "luahelper-lsp/langserver/check/common" 6 | "luahelper-lsp/langserver/check/compiler/ast" 7 | "luahelper-lsp/langserver/check/compiler/lexer" 8 | ) 9 | 10 | // 是否给常量赋值 当有a.b.c时,只判断a是否常量 若a是import值,则只判断b是否常量 11 | func (a *Analysis) checkEnum(node *ast.TableConstructorExp) { 12 | if len(node.KeyExps) == 0 { 13 | return 14 | } 15 | 16 | if !a.isNeedCheck() || a.realTimeFlag { 17 | return 18 | } 19 | 20 | if common.GConfig.IsGlobalIgnoreErrType(common.CheckErrorEnumValue) { 21 | return 22 | } 23 | 24 | fileResult := a.curResult 25 | 26 | // 判断枚举值是否有关联 27 | if !a.Projects.IsLineFragementEnum(fileResult.Name, node.Loc.StartLine) { 28 | return 29 | } 30 | 31 | var tableEnumList common.TableEnumList 32 | for i, keyExp := range node.KeyExps { 33 | valExp := node.ValExps[i] 34 | if valExp == nil { 35 | continue 36 | } 37 | 38 | strKeySimple := common.GetExpName(keyExp) 39 | itemNum, flag := tableEnumList.CheckEnumExp(strKeySimple, valExp) 40 | if !flag { 41 | tableEnumList.AddEnumVar(strKeySimple, keyExp, valExp) 42 | continue 43 | } 44 | 45 | errStr := fmt.Sprintf("table: enum %s and %s contains duplicate value", itemNum.FieldStr, strKeySimple) 46 | var relateVec []common.RelateCheckInfo 47 | oldKeyLoc := common.GetExpLoc(itemNum.KeyExp) 48 | oldValueLoc := common.GetExpLoc(itemNum.ValueExp) 49 | oldRangeLoc := lexer.GetRangeLoc(&oldKeyLoc, &oldValueLoc) 50 | 51 | relateVec = append(relateVec, common.RelateCheckInfo{ 52 | LuaFile: fileResult.Name, 53 | ErrStr: errStr, 54 | Loc: oldRangeLoc, 55 | }) 56 | 57 | expKeyLoc := common.GetExpLoc(keyExp) 58 | expValueLoc := common.GetExpLoc(valExp) 59 | rangeLoc := lexer.GetRangeLoc(&expKeyLoc, &expValueLoc) 60 | fileResult.InsertRelateError(common.CheckErrorEnumValue, errStr, rangeLoc, relateVec) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/analysis/analysis_check_loc_var.go: -------------------------------------------------------------------------------- 1 | package analysis 2 | 3 | import ( 4 | "fmt" 5 | "luahelper-lsp/langserver/check/common" 6 | ) 7 | 8 | func (a *Analysis) checkLocVarCall() { 9 | 10 | // 如果是一轮校验,判断是否要校验局部变量是否定义未使用 11 | if !a.isFirstTerm() || a.realTimeFlag { 12 | return 13 | } 14 | 15 | // 判断是否开启了局部变量定义了是否未使用的告警 16 | if common.GConfig.IsGlobalIgnoreErrType(common.CheckErrorLocalNoUse) { 17 | return 18 | } 19 | 20 | scope := a.curScope 21 | if scope == nil { 22 | return 23 | } 24 | 25 | fileResult := a.curResult 26 | 27 | // 扫描当前scope,判断哪些局部变量定义了未使用 28 | for varName, varInfoList := range scope.LocVarMap { 29 | // _ 局部变量忽略, _G也忽略 30 | if varName == "_" || varName == "_G" { 31 | continue 32 | } 33 | 34 | if common.GConfig.IsIgnoreLocNotUseVar(varName) { 35 | // 如果为系统忽略的局部变量定义了,未使用的,忽略掉 36 | continue 37 | } 38 | 39 | for _, oneVar := range varInfoList.VarVec { 40 | if oneVar.IsUse || oneVar.IsClose { 41 | continue 42 | } 43 | 44 | //定义的局部函数忽略 45 | if oneVar.ReferFunc != nil { 46 | continue 47 | } 48 | 49 | // 判断指向的关联变量,是否为系统的函数或模块 50 | // 例如 local math = math 这样的忽略掉 51 | expName := common.GetExpName(oneVar.ReferExp) 52 | 53 | // 1) 判断是否直接关联到的系统模块或函数 54 | oneStr := common.GetExpSubKey(expName) 55 | if oneStr != "" { 56 | if common.GConfig.IsInSysNotUseMap(oneStr) { 57 | // 为系统的模块或函数名,忽略掉 58 | continue 59 | } 60 | } 61 | 62 | // 2) 判断是否关联到系统模块的成员, 例如:local concat = table.concat 63 | flagG, strRet := common.StrRemovePreG(expName) 64 | if flagG { 65 | expName = "!" + strRet 66 | } 67 | moduleName, keyName := common.GetTableStrTwoStr(expName) 68 | if moduleName != "" && keyName != "" { 69 | if common.GConfig.IsInSysNotUseMap(moduleName) { 70 | // 为系统的模块或函数名,忽略掉 71 | continue 72 | } 73 | } 74 | 75 | errorStr := fmt.Sprintf("%s declared and not used", varName) 76 | fileResult.InsertError(common.CheckErrorLocalNoUse, errorStr, oneVar.Loc) 77 | 78 | // 遍历所有的定义了未使用,只是简单的赋值 79 | for _, subVar := range oneVar.NoUseAssignLocs { 80 | errorStr := fmt.Sprintf("%s declared and not used, this just assign", varName) 81 | fileResult.InsertError(common.CheckErrorNoUseAssign, errorStr, subVar) 82 | } 83 | 84 | // 清除掉 85 | oneVar.NoUseAssignLocs = nil 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/annotation/annotateast/annotate_ast_common.go: -------------------------------------------------------------------------------- 1 | package annotateast 2 | 3 | // FieldScopeType filed成员的属性类型:public、protected、private 4 | type FieldScopeType uint8 5 | 6 | const ( 7 | _ FieldScopeType = iota 8 | 9 | // FieldScopePublic public属性 10 | FieldScopePublic = 0 11 | 12 | // FieldScopeProtected protected属性 13 | FieldScopeProtected = 1 14 | 15 | // FieldScopePrivate private属性 16 | FieldScopePrivate = 2 17 | ) 18 | 19 | // FieldColonType filed成员的属性类型 是否为 : 的成员,默认不会 20 | type FieldColonType uint8 21 | 22 | const ( 23 | _ FieldColonType = iota 24 | 25 | // FieldColonNo 默认不为 :的成员 26 | FieldColonNo = 0 27 | 28 | // FieldColonYes 为 :的成员, 例如为下面的 29 | // ---@field FuncA : fun() : void 30 | FieldColonYes = 1 31 | 32 | // FieldColonHide 为隐藏 :的成员, 例如为下面的 33 | // ---@field AAA 34 | // ---@field FuncA fun(self:A) : void 35 | FieldColonHide = 2 36 | ) 37 | 38 | // EnumType 枚举类型start或end 39 | type EnumType uint8 40 | 41 | const ( 42 | _ EnumType = iota 43 | 44 | // EnumTypeNone 非枚举类型 45 | EnumTypeNone = 0 46 | 47 | // EnumTypeStart 枚举类型的开始 48 | EnumTypeStart = 1 49 | 50 | // EnumTypeEnd 枚举类型的结束 51 | EnumTypeEnd = 2 52 | ) 53 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/annotation/annotateast/annotate_fragment.go: -------------------------------------------------------------------------------- 1 | package annotateast 2 | 3 | // AnnotateFragment 一个片段的注释包含的所有结构, 一个代码注释片段包含多行,每一行大致是一个结构 4 | type AnnotateFragment struct { 5 | Stats []AnnotateState // 多个子state 6 | Lines []int // 每个state的行号 7 | } 8 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/annotation/annotateast/annotate_sample.go: -------------------------------------------------------------------------------- 1 | package annotateast 2 | 3 | // 分析注释功能 4 | 5 | // 自带的type类型有下面的 6 | // nil 7 | // boolean 8 | // number 9 | // function 10 | // userdata 11 | // thread 12 | // any 13 | // void 14 | // self 15 | 16 | // 1) type 用法的完整格式 17 | // ---@type MY_TYPE[|OTHER_TYPE] [@comment] 18 | // 可能是MY_TYPE 也有可能是OTHER_TYPE 19 | // Since lua is dynamic-typed, a variable may be of different types 20 | // use | to list all possible types 21 | 22 | // 描述多个的时候 23 | // ---@type MY_TYPE[|OTHER_TYPE], MY_TYPE[|OTHER_TYPE] [@comment] [@comment] 24 | 25 | // 2) class 的用法 26 | // ---@class MY_TYPE[:PARENT_TYPE] [@comment] 27 | 28 | // 多重继承的用法 29 | // ---@class MY_TYPE[:PARENT_TYPE], MY_TYPE[:PARENT_TYPE] [@comment] 30 | 31 | // 3) field 是class的成员,一般在@class的后面 32 | // ---@field [public|protected|private] field_name FIELDLTYPE[|OTHER_TYPE] [@comment] 33 | // class 允许有多个field成员,每个field成员占用一行 34 | 35 | // 4) fun 类型(函数的类型) 36 | // fun(param1:PARAM_TYPE1 [,param2:PARAM_TYPE2]): RETURN_TYPE1[, RETURN_TYPE2] 37 | 38 | // 5) return 函数的返回值 39 | // ---@return RETURN_TYPE[|OTHER_TYPE] [@comment1] 40 | // 5.1) 多个返回值,每个返回值之间用,分隔 41 | // ---@return RETURN_TYPE1[|OTHER_TYPE], RETURN_TYPE2[|OTHER_TYPE] [@comment1] [@comment2] 42 | 43 | // 5.2)如果有多个返回值,也可以分多行表示 44 | // ---@return RETURN_TYPE[|OTHER_TYPE] [@comment] 45 | // ---@return RETURN_TYPE[|OTHER_TYPE] [@comment] 46 | 47 | // 函数返回值的用法 48 | // ---@param one string @参数1是表示string1 49 | // ---@param two number @参数2是表示number1 50 | // ---@return number, number, string 51 | // function getRes(one, two) end 52 | 53 | // 6) overload 函数重载的支持 54 | /* 55 | ---@overload fun(list:table):string 56 | ---@overload fun(list:table, sep:string):string 57 | ---@overload fun(list:table, sep:string, i:number):string 58 | ---@param list table 59 | ---@param sep string 60 | ---@param i number 61 | ---@param j number 62 | ---@return string 63 | function table.concat(list, sep, i, j) end 64 | */ 65 | 66 | // 7 @param 函数参数 67 | //---@param param_name MY_TYPE[|other_type] [@comment] 68 | // 7.1 例子 69 | //---@param car Car 70 | //function setCar(car) end 71 | 72 | // 7.2 例子 73 | //---@param car Car 74 | //setCallback(function(car) end) 75 | 76 | // 7.3 例子 77 | //---@param car Car 78 | //for k, car in ipairs(list) end 79 | 80 | // 8 array type 81 | //---@type MY_TYPE[] @comment 82 | //二义性表达如下 83 | //---@type string | number[] 表示类型为string或是number的列表 84 | //---@type (string | number)[] 表示类型为string的列表或是number的列表 85 | //---@type string[] | number[] 表示类型为string的列表或是number的列表 86 | 87 | // 9 table type 88 | //---@type table 89 | 90 | // 10 alias 91 | //---@alias NEW_NAME TYPE 92 | 93 | //---@alias Handler fun(type: string, data: any):void 94 | //---@param handler Handler 95 | //function addHandler(handler) 96 | //end 97 | 98 | // 11 generic 泛型 99 | // ---@generic T1 [: PARENT_TYPE] [, T2 [: PARENT_TYPE]] 100 | 101 | //---@generic T : Transport, K 102 | //---@param param1 T 103 | //---@param param2 K 104 | //---@return T 105 | //function test(param1, param2) 106 | 107 | // 12 enum 枚举段类型【一个枚举段中定义的变量的值不能重复】 108 | //---@enum start @comment 表示枚举段的开始 109 | //---@enum end @comment 表示枚举段的结束 110 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/annotation/annotateast/annotate_type.go: -------------------------------------------------------------------------------- 1 | package annotateast 2 | 3 | import ( 4 | "luahelper-lsp/langserver/check/compiler/lexer" 5 | ) 6 | 7 | // 自带的type类型有下面的 8 | // nil 9 | // boolean 10 | // number 11 | // function 12 | // userdata 13 | // thread 14 | // table 15 | // any 16 | // void 17 | 18 | // type的所有用法 19 | // 用法的完整格式 20 | // ---@type MY_TYPE{|OTHER_TYPE]} [@comment] 21 | 22 | // Type 注解类型的空接口 23 | type Type interface{} 24 | 25 | // NormalType 普通的类型 26 | type NormalType struct { 27 | StrName string // 关联的类型的字符串名字(或是alias的名字) 28 | NameLoc lexer.Location // 简单类型的位置信息 29 | ShowColor bool // 着色的时候,显示位置 30 | } 31 | 32 | // MultiType 多种类型,选择其中一种都可以 33 | type MultiType struct { 34 | Loc lexer.Location // 整个func包含的位置信息 35 | TypeList []Type // 多种类型的list 36 | } 37 | 38 | // ArrayType 关联的array 列表类型 39 | type ArrayType struct { 40 | Loc lexer.Location // 整个包含的位置信息 41 | ItemType Type // 里面的类型,又是Type的一种 42 | } 43 | 44 | // TableType 关联的table map类型 45 | type TableType struct { 46 | Loc lexer.Location // 整个包含的位置信息 47 | TableStrLoc lexer.Location // table这个字符串的位置信息 48 | EmptyFlag bool // 是否为空的table,不包含key或value 49 | KeyType Type // 里面的key类型,又是Type的一种 50 | ValueType Type // 里面的Value类型,又是Type的一种 51 | } 52 | 53 | // FuncType 函数的类型 54 | type FuncType struct { 55 | Loc lexer.Location // 整个func包含的位置信息 56 | FunLoc lexer.Location // fun关键字的位置信息,需要特殊着色 57 | ParamNameList []string // 函数参数名称的列表 58 | ParamNameLocList []lexer.Location // 整个参数列表的的位置信息 59 | ParamTypeList []Type // 函数参数类型的列表 60 | ParamOptionList []bool // 参数是否为可选的,如果为这样的 one? : string 表示参数one是可选的 61 | ReturnTypeList []Type // 函数返回值的列表 62 | } 63 | 64 | // ConstType 常量类型,例如 "aa" | "bb" 65 | type ConstType struct { 66 | Loc lexer.Location // 位置信息 67 | Name string // 名称 68 | QuotesFlag bool // 是否为字符串双引号标记 String double quotes 69 | Comment string // 额外注释说明 70 | } 71 | 72 | // NotValidType 不是有效的 73 | type NotValidType struct { 74 | } 75 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/annotation/annotatelexer/annotate_lexer_common.go: -------------------------------------------------------------------------------- 1 | package annotatelexer 2 | 3 | import ( 4 | "luahelper-lsp/langserver/check/compiler/lexer" 5 | ) 6 | 7 | // AnnotateErrType 错误的类型 8 | type AnnotateErrType int 9 | 10 | const ( 11 | // AErrorOk 正常的 12 | AErrorOk AnnotateErrType = 0 13 | 14 | // AErrorToken 没有切出正确的切词 15 | AErrorToken AnnotateErrType = 1 16 | 17 | // AErrorKind 语法错误 18 | AErrorKind AnnotateErrType = 2 19 | 20 | // AErrorType 注解类型的错误 21 | AErrorType AnnotateErrType = 3 22 | 23 | // AErrorNormalIdentifier 普通标识符 24 | AErrorNormalIdentifier AnnotateErrType = 4 25 | 26 | // AErrorTypeIdentifier 类型注解标识符出错 27 | AErrorTypeIdentifier AnnotateErrType = 5 28 | ) 29 | 30 | // ParseAnnotateErr check的错误信息 31 | type ParseAnnotateErr struct { 32 | ErrType AnnotateErrType // 错误的类型 33 | NeedKind ATokenType // 当为AErrorKind类型不匹配的时候,保存需要的kind 34 | ErrStr string // 简单的错误信息 35 | ShowStr string // 完整的错误信息 36 | ErrToken AnnotateToken // 出错的之前token 37 | NowToken AnnotateToken // 当前的token 38 | ErrLoc lexer.Location // 出错的位置信息 39 | } 40 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/annotation/annotatelexer/annotate_token.go: -------------------------------------------------------------------------------- 1 | package annotatelexer 2 | 3 | // ATokenType 类型 4 | type ATokenType int8 5 | 6 | const ( 7 | ATokenEOF ATokenType = iota // end-of-file 8 | ATokenSepComma // , 9 | ATokenSepColon // : 10 | ATokenVararg // ... 函数的可变参数 11 | ATokenVSepLparen // ( 12 | ATokenVSepRparen // ) 13 | ATokenVSepLbrack // [ 14 | ATokenVSepRbrack // ] 15 | ATokenBor // | 16 | ATokenLt // < 17 | ATokenGt // > 18 | ATokenAt // @ 19 | ATokenOption // ? 20 | ATokenString // 定义的其他字符串 21 | ATokenKwFun // fun 22 | ATokenKwTable // table 23 | ATokenKwType // type 24 | ATokenKwParam // param 25 | ATokenKwField // field 26 | ATokenKwClass // class 27 | ATokenKwReturn // return 28 | ATokenKwOverload // overload 29 | ATokenKwAlias // alias 30 | ATokenKwGeneric // generic 31 | ATokenKwPubic // public 32 | ATokenKwProtected // protected 33 | ATokenKwPrivate // private 34 | ATokenKwVararg // vararg 35 | ATokenKwIdentifier // identifier 36 | ATokenKwConst // const 37 | ATokenKwOther // other token, not valid 38 | ATokenKwEnum // enum 枚举段关键值 39 | ATokenKwEnumStart // start enum后面跟着的开始关键字,例如完整的为enum start 40 | ATokenKwEnumEnd // end enum后面跟着的结束关键字,例如完整的为enum end 41 | ) 42 | 43 | var keywords = map[string]ATokenType{ 44 | "fun": ATokenKwFun, 45 | "table": ATokenKwTable, 46 | "type": ATokenKwType, 47 | "param": ATokenKwParam, 48 | "field": ATokenKwField, 49 | "class": ATokenKwClass, 50 | "return": ATokenKwReturn, 51 | "overload": ATokenKwOverload, 52 | "alias": ATokenKwAlias, 53 | "generic": ATokenKwGeneric, 54 | "public": ATokenKwPubic, 55 | "protected": ATokenKwProtected, 56 | "private": ATokenKwPrivate, 57 | "vararg": ATokenKwVararg, 58 | "const": ATokenKwConst, 59 | "enum": ATokenKwEnum, 60 | } 61 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/annotation/annotateparser/string_util.go: -------------------------------------------------------------------------------- 1 | package annotateparser 2 | 3 | import "strings" 4 | 5 | // 字符串去掉单引号或双引号 6 | func splitStrQuotes(str string) (splitStr string, quetesFlag bool) { 7 | splitStr = str 8 | if len(str) <= 2 { 9 | return 10 | } 11 | 12 | if strings.HasPrefix(str, "'") && strings.HasSuffix(str, "'") { 13 | splitStr = string(str[1 : len(str)-1]) 14 | quetesFlag = true 15 | return 16 | } 17 | 18 | if strings.HasPrefix(str, "\"") && strings.HasSuffix(str, "\"") { 19 | splitStr = string(str[1 : len(str)-1]) 20 | quetesFlag = true 21 | return 22 | } 23 | 24 | return 25 | } 26 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/check_color_file.go: -------------------------------------------------------------------------------- 1 | package check 2 | 3 | import ( 4 | "luahelper-lsp/langserver/check/analysis" 5 | "luahelper-lsp/langserver/check/common" 6 | "luahelper-lsp/langserver/check/results" 7 | "luahelper-lsp/langserver/log" 8 | "luahelper-lsp/langserver/pathpre" 9 | "time" 10 | ) 11 | 12 | // FindAllColorVar 查找文件中的所有全局变量 13 | func (a *AllProject) FindAllColorVar(strFile string) (colorResult map[common.ColorType]*common.OneColorResut) { 14 | // 如果为局部变量,只在当前文件查找 15 | color := results.CreateColorFileInfo(strFile) 16 | 17 | // 1) 获取变量的着色 18 | a.handleFindVarColor(color) 19 | if color.FileResult == nil { 20 | return 21 | } 22 | 23 | // 当前文件的所有全局变量定义,也插入其中 24 | for _, oneVar := range color.FileResult.GlobalMaps { 25 | color.InsertOneGlobalColor(oneVar, &(oneVar.Loc)) 26 | } 27 | 28 | // 2) 获取这个文件静态的注解产生的着色, 临时把这个颜色放入到全局变量着色里面 29 | // anntotateLocVec := a.getAnnotateColor(strFile) 30 | // if len(anntotateLocVec) > 0 { 31 | // oneColor := color.ColorResult[common.CTAnnotate] 32 | // if oneColor == nil { 33 | // oneColor := &common.OneColorResut{ 34 | // LocVec: make([]lexer.LocInfo, 0, 1), 35 | // } 36 | // oneColor.LocVec = anntotateLocVec 37 | // color.ColorResult[common.CTAnnotate] = oneColor 38 | // } else { 39 | // oneColor.LocVec = append(oneColor.LocVec, anntotateLocVec...) 40 | // } 41 | // } 42 | 43 | colorResult = color.ColorResult 44 | return 45 | } 46 | 47 | func (a *AllProject) handleFindVarColor(color *results.ColorFileResult) { 48 | strFile := pathpre.GetRemovePreStr(color.StrFile) 49 | fileStruct := a.getVailidCacheFileStruct(strFile) 50 | if fileStruct == nil { 51 | log.Error("handleOneFile file not valid file=%s", strFile) 52 | return 53 | } 54 | fileResult := fileStruct.FileResult 55 | 56 | time1 := time.Now() 57 | 58 | // 创建第三轮遍历的包裹对象 59 | analysis := analysis.CreateAnalysis(results.CheckTermFive, color.StrFile) 60 | analysis.ColorResult = color 61 | analysis.Projects = a 62 | analysis.HandleTermTraverseAST(results.CheckTermFive, fileResult, nil) 63 | 64 | ftime := time.Since(time1).Milliseconds() 65 | log.Debug("handleFindVarColor handleOneFile %s, cost time=%d(ms)", strFile, ftime) 66 | } 67 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/check_common.go: -------------------------------------------------------------------------------- 1 | package check 2 | 3 | import ( 4 | "luahelper-lsp/langserver/check/common" 5 | "luahelper-lsp/langserver/check/compiler/lexer" 6 | "luahelper-lsp/langserver/check/results" 7 | ) 8 | 9 | // CommonFuncParam 公共的代码传参 10 | type CommonFuncParam struct { 11 | fileResult *results.FileResult 12 | fi *common.FuncInfo 13 | scope *common.ScopeInfo 14 | loc lexer.Location 15 | secondProject *results.SingleProjectResult 16 | thirdStruct *results.AnalysisThird 17 | } 18 | 19 | // SliceInsert2 字符串切片拼接 20 | func SliceInsert2(s *[]string, index int, value string) { 21 | rear := append([]string{}, (*s)[index:]...) 22 | *s = append(append((*s)[:index], value), rear...) 23 | } 24 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/common/annotate_enum.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "luahelper-lsp/langserver/check/annotation/annotateast" 5 | ) 6 | 7 | type AnnotateEnumStack struct { 8 | Slice []*annotateast.AnnotateEnumState 9 | } 10 | 11 | func (s *AnnotateEnumStack) Push(val *annotateast.AnnotateEnumState) { 12 | s.Slice = append(s.Slice, val) 13 | } 14 | 15 | func (s *AnnotateEnumStack) Pop() (val *annotateast.AnnotateEnumState) { 16 | if len(s.Slice) == 0 { 17 | return nil 18 | } 19 | 20 | index := len(s.Slice) - 1 21 | val = s.Slice[index] 22 | s.Slice = s.Slice[:index] 23 | return val 24 | } 25 | 26 | func (s *AnnotateEnumStack) Len() int { 27 | return len(s.Slice) 28 | } 29 | 30 | func (s *AnnotateEnumStack) Peek() (val *annotateast.AnnotateEnumState) { 31 | if len(s.Slice) == 0 { 32 | return nil 33 | } 34 | 35 | return s.Slice[len(s.Slice)-1] 36 | } 37 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/common/cache_lru.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "container/list" 5 | "errors" 6 | "sync" 7 | ) 8 | 9 | // CacheNode LRU Node 10 | type CacheNode struct { 11 | Key, Value interface{} 12 | } 13 | 14 | // NewCacheNode 创建一个节点指针 15 | func (cnode *CacheNode) NewCacheNode(k, v interface{}) *CacheNode { 16 | return &CacheNode{k, v} 17 | } 18 | 19 | // LRUCache 整体封装结构 20 | type LRUCache struct { 21 | Capacity int 22 | dlist *list.List 23 | cacheMap map[interface{}]*list.Element 24 | cacheMutex sync.Mutex 25 | } 26 | 27 | // NewLRUCache 创建一个整体封装结构指针 28 | func NewLRUCache(cap int) *LRUCache { 29 | return &LRUCache{ 30 | Capacity: cap, 31 | dlist: list.New(), 32 | cacheMap: make(map[interface{}]*list.Element)} 33 | } 34 | 35 | // Size 返回目前的容量 36 | func (lru *LRUCache) Size() int { 37 | return lru.dlist.Len() 38 | } 39 | 40 | // Set 插入一个节点 41 | func (lru *LRUCache) Set(k, v interface{}) error { 42 | lru.cacheMutex.Lock() 43 | defer lru.cacheMutex.Unlock() 44 | 45 | if lru.dlist == nil { 46 | return errors.New("LRUCache Not Initial") 47 | } 48 | 49 | if pElement, ok := lru.cacheMap[k]; ok { 50 | lru.dlist.MoveToFront(pElement) 51 | pElement.Value.(*CacheNode).Value = v 52 | return nil 53 | } 54 | 55 | newElement := lru.dlist.PushFront(&CacheNode{k, v}) 56 | lru.cacheMap[k] = newElement 57 | 58 | if lru.dlist.Len() > lru.Capacity { 59 | //移掉最后一个 60 | lastElement := lru.dlist.Back() 61 | if lastElement == nil { 62 | return nil 63 | } 64 | cacheNode := lastElement.Value.(*CacheNode) 65 | delete(lru.cacheMap, cacheNode.Key) 66 | lru.dlist.Remove(lastElement) 67 | } 68 | return nil 69 | } 70 | 71 | // Get 返回节点 72 | func (lru *LRUCache) Get(k interface{}) (v interface{}, ret bool, err error) { 73 | lru.cacheMutex.Lock() 74 | defer lru.cacheMutex.Unlock() 75 | 76 | if lru.cacheMap == nil { 77 | return v, false, errors.New("LRUCache Not Initial") 78 | } 79 | 80 | if pElement, ok := lru.cacheMap[k]; ok { 81 | lru.dlist.MoveToFront(pElement) 82 | return pElement.Value.(*CacheNode).Value, true, nil 83 | } 84 | return v, false, nil 85 | } 86 | 87 | // Remove 删除节点 88 | func (lru *LRUCache) Remove(k interface{}) bool { 89 | lru.cacheMutex.Lock() 90 | defer lru.cacheMutex.Unlock() 91 | 92 | if lru.cacheMap == nil { 93 | return false 94 | } 95 | 96 | if pElement, ok := lru.cacheMap[k]; ok { 97 | cacheNode := pElement.Value.(*CacheNode) 98 | delete(lru.cacheMap, cacheNode.Key) 99 | lru.dlist.Remove(pElement) 100 | return true 101 | } 102 | return false 103 | } 104 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/common/enum_info.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "luahelper-lsp/langserver/check/compiler/ast" 5 | ) 6 | 7 | // 定义枚举类型关联的值 8 | type enumVar struct { 9 | VarStr string // 枚举变量的名称 10 | VarInfo *VarInfo // 枚举变量的信息 11 | } 12 | 13 | // 定义枚举类型的值列表 14 | type EnumVacList struct { 15 | EnumVarVec []*enumVar 16 | } 17 | 18 | // AddEnumVar 添加枚举变量 19 | func (e *EnumVacList) AddEnumVar(varStr string, varInfo *VarInfo) { 20 | e.EnumVarVec = append(e.EnumVarVec, &enumVar{ 21 | VarStr: varStr, 22 | VarInfo: varInfo, 23 | }) 24 | } 25 | 26 | // CheckEnumVar 检查枚举变量指向的值是否存在 27 | func (e *EnumVacList) CheckEnumVar(varStr string, varInfo *VarInfo) (oldStr string, oldVar *VarInfo, 28 | flag bool) { 29 | for _, enumVar := range e.EnumVarVec { 30 | if varInfo.CheckVarIsSample(enumVar.VarInfo) { 31 | return enumVar.VarStr, enumVar.VarInfo, true 32 | } 33 | } 34 | 35 | return "", nil, false 36 | } 37 | 38 | // Len 注解错误排序相关的获取长度的函数 39 | func (e *EnumVacList) Len() int { return len(e.EnumVarVec) } 40 | 41 | // Less 注解错误排序比较的函数 42 | func (e *EnumVacList) Less(i, j int) bool { 43 | oneLoc := e.EnumVarVec[i].VarInfo.Loc 44 | twoLoc := e.EnumVarVec[j].VarInfo.Loc 45 | if oneLoc.StartLine == twoLoc.StartLine { 46 | return oneLoc.StartColumn < twoLoc.StartColumn 47 | } 48 | 49 | return oneLoc.StartLine < twoLoc.StartLine 50 | } 51 | 52 | // Swap 注解错误排序较好的函数 53 | func (e *EnumVacList) Swap(i, j int) { 54 | e.EnumVarVec[i], e.EnumVarVec[j] = e.EnumVarVec[j], e.EnumVarVec[i] 55 | } 56 | 57 | type tableEnumItem struct { 58 | FieldStr string 59 | KeyExp ast.Exp 60 | ValueExp ast.Exp 61 | } 62 | 63 | // 定义枚举类型的值列表 64 | type TableEnumList struct { 65 | enumItemVec []*tableEnumItem 66 | } 67 | 68 | // AddEnumVar 添加枚举变量 69 | func (t *TableEnumList) AddEnumVar(varStr string, keyExp, valueExp ast.Exp) { 70 | t.enumItemVec = append(t.enumItemVec, &tableEnumItem{ 71 | FieldStr: varStr, 72 | KeyExp: keyExp, 73 | ValueExp: valueExp, 74 | }) 75 | } 76 | 77 | // CheckEnumVar 检查枚举变量指向的值是否存在 78 | func (t *TableEnumList) CheckEnumExp(varStr string, exp ast.Exp) (enumItem *tableEnumItem, 79 | flag bool) { 80 | for _, enumItem := range t.enumItemVec { 81 | if CheckExpRefIsSample(exp, enumItem.ValueExp) { 82 | return enumItem, true 83 | } 84 | } 85 | 86 | return nil, false 87 | } 88 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/common/err_info.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | // CheckErrorType 检查错误的类型 4 | type CheckErrorType int 5 | 6 | const ( 7 | _ CheckErrorType = iota 8 | 9 | // CheckErrorSyntax 语法分析阶段出错,构造ast树有问题,无法继续进行,重大错误 10 | CheckErrorSyntax = 1 11 | 12 | // CheckErrorNoDefine 变量未找到的定义 13 | CheckErrorNoDefine = 2 14 | 15 | // CheckErrorCycleDefine 因循环依赖或是加载顺序导致的变量未定义 16 | CheckErrorCycleDefine = 3 17 | 18 | // CheckErrorLocalNoUse 定义了的局部变量未使用 19 | CheckErrorLocalNoUse = 4 20 | 21 | // CheckErrorTableDuplicateKey table中是否有重复的key 22 | CheckErrorTableDuplicateKey = 5 23 | 24 | // CheckErrorNoFile 指定加载文件,但是没有发现文件 25 | CheckErrorNoFile = 6 26 | 27 | // CheckErrorAssignParamNum 赋值语句时候,参数个数不匹配,例如 a,b=c,d,e;后面的赋值个数多余前面的 28 | CheckErrorAssignParamNum = 7 29 | 30 | // CheckErrorLocalParamNum 局部变量定义时候,参数个数不匹配,例如 local a = b,c;后面的参数多余前面的 31 | CheckErrorLocalParamNum = 8 32 | 33 | // CheckErrorGotoLabel goto时找不到对应的label标记 34 | CheckErrorGotoLabel = 9 35 | 36 | // CheckErrorCallParam 函数调用参数数量出错 37 | CheckErrorCallParam = 10 38 | 39 | // CheckErrorImportVar 引用import其他lua文件,例如 local a = import("one.lua");调用a.bbb, 其中bbb在引用的one.lua文件中未定义 40 | CheckErrorImportVar = 11 41 | 42 | // CheckErrorNotIfVar 前面 if not aa then,后面调用了aa.bb的变量 43 | CheckErrorNotIfVar = 12 44 | 45 | // CheckErrorDuplicateParam 函数定义的参数重复了 46 | CheckErrorDuplicateParam = 13 47 | 48 | // CheckErrorDuplicateExp 二元表达式 两边的表达式是否一样,一样进行告警 49 | CheckErrorDuplicateExp = 14 50 | 51 | // CheckErrorOrAlwaysTrue 二元表达式 or 永远为true,例如 a = a or true ,始终为true 52 | CheckErrorOrAlwaysTrue = 15 53 | 54 | // CheckErrorAndAlwaysFalse 二元表达式 and 永远为false,例如 a = a and false, 始终为false 55 | CheckErrorAndAlwaysFalse = 16 56 | 57 | // CheckErrorNoUseAssign 定义了的局部变量未使用, 后面只是简短的赋值 58 | CheckErrorNoUseAssign = 17 59 | 60 | // CheckErrorAnnotate 注解系统引入的错误 61 | CheckErrorAnnotate = 18 62 | 63 | // 分支条件重复 64 | CheckErrorDuplicateIf = 19 65 | 66 | // 变量自身赋值 67 | CheckErrorSelfAssign = 20 68 | 69 | // 浮点数做等于或不等于判断 70 | CheckErrorFloatEq = 21 71 | 72 | // 错误的成员变量 73 | CheckErrorClassField = 22 74 | 75 | // 给常量赋值 76 | CheckErrorConstAssign = 23 77 | 78 | // 函数调用参数类型出错 79 | CheckErrorCallParamType = 24 80 | 81 | // 函数返回值类型出错 82 | CheckErrorFuncRetErr = 25 83 | 84 | // 赋值表达式改变了类型 85 | CheckErrorAssignType = 26 86 | 87 | // 二元运算表达式类型不同 88 | CheckErrorBinopType = 27 89 | 90 | // local函数未调用(可选,由于lua中可以隐式调用函数,所以不一定准确,全局函数,rpc函数更是如此) 91 | CheckErrorLocFuncNotCall = 28 92 | 93 | // 枚举代码段中的指向的变量值不能重复 94 | CheckErrorEnumValue = 29 95 | 96 | // CheckErrorMax 97 | CheckErrorMax = 30 98 | ) 99 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/common/file_index_info.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import "strings" 4 | 5 | // // FileDirSturct 文件的层级目录结构 6 | // type FileDirSturct struct { 7 | // CurDir string // 当前的目录,例如 g:/compangyproject 8 | // FilesMap map[string]struct{} // 该目录下包含的具体的lua文件。全路径,例如为:g:/compangyproject/one.lua 9 | // SubDirList map[string]*FileDirSturct // 当前目录下,包含的所有子文件夹,嵌套的结构 10 | // } 11 | 12 | // // GetFirstContentDir 递归向下获取第一个包含有用内容的子目录 13 | // func (f *FileDirSturct) GetFirstContentDir() *FileDirSturct { 14 | // if len(f.FilesMap) == 0 && len(f.SubDirList) == 1 { 15 | // for _, subDir := range f.SubDirList { 16 | // return subDir.GetFirstContentDir() 17 | // } 18 | // return nil 19 | // } 20 | 21 | // return f 22 | // } 23 | 24 | // FileIndexInfo 文件索引信息,文件名映射到全路径 25 | type FileIndexInfo struct { 26 | fileNameMap map[string](map[string]string) // 文件名(包括后缀名)映射到所有的完整路径 27 | freFileNameMap map[string](map[string]string) // 文件名(不包括后缀名)映射到所有的完整路径 28 | } 29 | 30 | // CreateFileIndexInfo 创建文件索引对象 31 | func CreateFileIndexInfo() *FileIndexInfo { 32 | return &FileIndexInfo{ 33 | fileNameMap: map[string](map[string]string){}, 34 | freFileNameMap: map[string](map[string]string){}, 35 | } 36 | } 37 | 38 | // InsertOneFile 缓存中插入一个文件名 39 | func (f *FileIndexInfo) InsertOneFile(strFile string) { 40 | // CompleteFilePathToPreStr 41 | strVec := strings.Split(strFile, "/") 42 | fileName := strVec[len(strVec)-1] 43 | 44 | completePathToPreStr := CompleteFilePathToPreStr(strFile) 45 | if valeMap, ok := f.fileNameMap[fileName]; ok { 46 | valeMap[strFile] = completePathToPreStr 47 | } else { 48 | f.fileNameMap[fileName] = map[string]string{} 49 | f.fileNameMap[fileName][strFile] = completePathToPreStr 50 | } 51 | 52 | seperateIndex := strings.Index(fileName, ".") 53 | if seperateIndex < 0 { 54 | return 55 | } 56 | 57 | preStr := fileName[0:seperateIndex] 58 | if valeMap, ok := f.freFileNameMap[preStr]; ok { 59 | valeMap[strFile] = completePathToPreStr 60 | } else { 61 | f.freFileNameMap[preStr] = map[string]string{} 62 | f.freFileNameMap[preStr][strFile] = completePathToPreStr 63 | } 64 | } 65 | 66 | // RemoveOneFile 清除指定的文件 67 | func (f *FileIndexInfo) RemoveOneFile(strFile string) { 68 | strVec := strings.Split(strFile, "/") 69 | fileName := strVec[len(strVec)-1] 70 | if valeMap, ok := f.fileNameMap[fileName]; ok { 71 | delete(valeMap, fileName) 72 | } 73 | 74 | seperateIndex := strings.Index(fileName, ".") 75 | if seperateIndex < 0 { 76 | return 77 | } 78 | 79 | preStr := fileName[0:seperateIndex] 80 | if valeMap, ok := f.freFileNameMap[preStr]; ok { 81 | delete(valeMap, preStr) 82 | } 83 | } 84 | 85 | // GetFileNameMap 获取文件名(包括后缀名)映射的所有文件名称 86 | func (f *FileIndexInfo) GetFileNameMap(strFile string) map[string]string { 87 | return f.fileNameMap[strFile] 88 | } 89 | 90 | // GetPreFileNameMap 获取文件名(不包括后缀名)映射的所有文件名称 91 | func (f *FileIndexInfo) GetPreFileNameMap(strFile string) map[string]string { 92 | return f.freFileNameMap[strFile] 93 | } 94 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/common/refer_info.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "luahelper-lsp/langserver/check/compiler/lexer" 5 | ) 6 | 7 | // ReferType 引用文件的类型 8 | type ReferType int 9 | 10 | const ( 11 | _ ReferType = iota 12 | // ReferNotValid 为无效的 13 | ReferNotValid = 0 14 | 15 | // ReferTypeFrame 框架自定义引入的方式 16 | ReferTypeFrame = 1 17 | 18 | // ReferTypeDofile dofile 19 | ReferTypeDofile = 2 20 | 21 | //ReferTypeLoadfile loadfile 22 | ReferTypeLoadfile = 3 23 | 24 | // ReferTypeRequire require 25 | ReferTypeRequire = 4 26 | ) 27 | 28 | // ReferFrameType 当为框架引入一个文件时候,具体的引入方式 29 | type ReferFrameType int 30 | 31 | const ( 32 | _ ReferFrameType = iota 33 | 34 | // RtypeImport 为自定义的import引入方式 35 | RtypeImport = 0 36 | 37 | // RtypeRequire 为类似require 38 | RtypeRequire = 1 39 | 40 | // RtypeAuto import和require都有可能。看引入文件的是否有返回,如果返回是一个table,那就是require,否则是import 41 | RtypeAuto = 2 42 | 43 | // RtypeNotValid 无效的 44 | RtypeNotValid = 3 45 | ) 46 | 47 | // ReferInfo 单个lua文件中,显示引用了其他的lua文件或是库 48 | // 例如 import("one.lua") 49 | type ReferInfo struct { 50 | ReferTypeStr string // 引用类型的真实名称,例如用户定制的import或是import1 51 | ReferType ReferType // 引用的类型 import, dofile, loadfile, require 52 | ReferStr string // 引用指向的名称,例如 one.lua 53 | ReferValidStr string // 引用指向的有效lua文件,例如require("two"), 实际上是引用的two.lua, 如果为空表示忽略引入的,可能是引入的.so 54 | Loc lexer.Location // 具体的位置信息 55 | ReferVarLocal bool // 引用如果赋值给了变量,true表示赋值的变量是否为local变量 56 | Valid bool // 第一遍check AST是否有效,如果无效,引用不用跟入进去分析,默认为true 57 | } 58 | 59 | // CreateOneReferInfo 创建一个引用信息 60 | func CreateOneReferInfo(referTypeStr, referStr string, loc lexer.Location) *ReferInfo { 61 | referType := StrToReferType(referTypeStr) 62 | if referType == ReferNotValid { 63 | return nil 64 | } 65 | 66 | return &ReferInfo{ 67 | ReferTypeStr: referTypeStr, 68 | ReferType: referType, 69 | ReferStr: referStr, 70 | ReferValidStr: "", 71 | ReferVarLocal: false, 72 | Valid: true, 73 | Loc: loc, 74 | } 75 | } 76 | 77 | // StrToReferType 字符串转换为对应的ReferType 78 | func StrToReferType(referTypeStr string) (referType ReferType) { 79 | if referTypeStr == "dofile" { 80 | referType = ReferTypeDofile 81 | } else if referTypeStr == "loadfile" { 82 | referType = ReferTypeLoadfile 83 | } else if referTypeStr == "require" { 84 | referType = ReferTypeRequire 85 | } else { 86 | if GConfig.IsFrameReferOtherFile(referTypeStr) { 87 | referType = ReferTypeFrame 88 | } else { 89 | referType = ReferNotValid 90 | } 91 | } 92 | 93 | return 94 | } 95 | 96 | // GetReferComment 获取引用信息的字符串,用于代码提示用 97 | func (refer *ReferInfo) GetReferComment() string { 98 | return refer.ReferTypeStr + "(\"" + refer.ReferStr + "\")" 99 | } 100 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/compiler/ast/attr.go: -------------------------------------------------------------------------------- 1 | package ast 2 | 3 | // LocalAttr local var attribute 4 | type LocalAttr uint8 // attribute type for local varible 5 | 6 | const ( 7 | // VDKREG no attr 8 | VDKREG LocalAttr = 0 9 | // RDKTOCLOSE close attr 10 | RDKTOCLOSE LocalAttr = 1 11 | // RDKCONST const attr 12 | RDKCONST LocalAttr = 2 13 | ) 14 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/compiler/ast/block.go: -------------------------------------------------------------------------------- 1 | package ast 2 | 3 | import ( 4 | "luahelper-lsp/langserver/check/compiler/lexer" 5 | ) 6 | 7 | // chunk ::= block 8 | // type Chunk *Block 9 | 10 | // Block code block 11 | // block ::= {stat} [retstat] 12 | // retstat ::= return [explist] [';'] 13 | // explist ::= exp {',' exp}} 14 | type Block struct { 15 | Stats []Stat 16 | RetExps []Exp 17 | Loc lexer.Location 18 | } 19 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/compiler/ast/stat.go: -------------------------------------------------------------------------------- 1 | package ast 2 | 3 | import ( 4 | "luahelper-lsp/langserver/check/compiler/lexer" 5 | ) 6 | 7 | /* 8 | stat ::= ‘;’ | 9 | varlist ‘=’ explist | 10 | functioncall | 11 | label | 12 | break | 13 | goto Name | 14 | do block end | 15 | while exp do block end | 16 | repeat block until exp | 17 | if exp then block {elseif exp then block} [else block] end | 18 | for Name ‘=’ exp ‘,’ exp [‘,’ exp] do block end | 19 | for namelist in explist do block end | 20 | function funcname funcbody | 21 | local function Name funcbody | 22 | local namelist [‘=’ explist] 23 | */ 24 | 25 | // Stat 空接口 26 | type Stat interface{} 27 | 28 | // EmptyStat 空的 29 | type EmptyStat struct{} // ‘;’ 30 | 31 | // BreakStat break语句 32 | // break 33 | type BreakStat struct { 34 | //Loc lexer.LocInfo 35 | } 36 | 37 | // LabelStat goto对应的标识符 38 | // ‘::’ Name ‘::’ 39 | type LabelStat struct { 40 | Name string 41 | Loc lexer.Location 42 | } 43 | 44 | // GotoStat goto语句 45 | // goto Name 46 | type GotoStat struct { 47 | Name string 48 | Loc lexer.Location 49 | } 50 | 51 | // DoStat do代码块 52 | // do block end 53 | type DoStat struct { 54 | Block *Block 55 | Loc lexer.Location 56 | } 57 | 58 | // FuncCallStat 函数调用 59 | type FuncCallStat = FuncCallExp // functioncall 60 | 61 | // IfStat if代码块 62 | // if exp then block {elseif exp then block} [else block] end 63 | type IfStat struct { 64 | Exps []Exp 65 | Blocks []*Block 66 | Loc lexer.Location 67 | } 68 | 69 | // WhileStat while代码块 70 | // while exp do block end 71 | type WhileStat struct { 72 | Exp Exp 73 | Block *Block 74 | Loc lexer.Location 75 | } 76 | 77 | // RepeatStat repeat 代码块 78 | // repeat block until exp 79 | type RepeatStat struct { 80 | Block *Block 81 | Exp Exp 82 | Loc lexer.Location 83 | } 84 | 85 | // ForNumStat for 整数遍历 86 | // for Name ‘=’ exp ‘,’ exp [‘,’ exp] do block end 87 | type ForNumStat struct { 88 | VarName string 89 | VarLoc lexer.Location 90 | InitExp Exp 91 | LimitExp Exp 92 | StepExp Exp 93 | Block *Block 94 | Loc lexer.Location 95 | } 96 | 97 | // ForInStat for语句 98 | // for namelist in explist do block end 99 | // namelist ::= Name {‘,’ Name} 100 | // explist ::= exp {‘,’ exp} 101 | type ForInStat struct { 102 | NameList []string 103 | NameLocList []lexer.Location // 所有变量的位置信息 104 | ExpList []Exp 105 | Block *Block 106 | Loc lexer.Location 107 | } 108 | 109 | // AssignStat 赋值语句 110 | // varlist ‘=’ explist 111 | // varlist ::= var {‘,’ var} 112 | // var ::= Name | prefixexp ‘[’ exp ‘]’ | prefixexp ‘.’ Name 113 | type AssignStat struct { 114 | VarList []Exp 115 | ExpList []Exp 116 | Loc lexer.Location 117 | } 118 | 119 | // LocalVarDeclStat 局部变量定义 120 | // local namelist [‘=’ explist] 121 | // namelist ::= Name {‘,’ Name} 122 | // explist ::= exp {‘,’ exp} 123 | type LocalVarDeclStat struct { 124 | NameList []string 125 | VarLocList []lexer.Location // 所有变量的位置信息 126 | AttrList []LocalAttr // 变量的属性 127 | ExpList []Exp 128 | Loc lexer.Location 129 | } 130 | 131 | // LocalFuncDefStat local function Name funcbody 132 | type LocalFuncDefStat struct { 133 | Name string 134 | NameLoc lexer.Location // 函数名的位置信息 135 | Exp *FuncDefExp 136 | Loc lexer.Location // 整体函数的位置信息 137 | } 138 | 139 | // IllegalStat Illegal stat token 140 | type IllegalStat struct { 141 | Name string 142 | Loc lexer.Location 143 | } -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/compiler/lexer/common.go: -------------------------------------------------------------------------------- 1 | package lexer 2 | 3 | // Location line and colomn 4 | type Location struct { 5 | StartLine int // from 1 6 | StartColumn int // from 1 7 | EndLine int 8 | EndColumn int 9 | } 10 | 11 | // ParseError check的错误信息 12 | type ParseError struct { 13 | ErrStr string // 简单的错误信息 14 | Loc Location // 错误的位置区域 15 | ReadFileErr bool // 读取文件是否失败 16 | } 17 | 18 | // TooManyErr 当Parse太多语法错误的时候,终止 19 | type TooManyErr struct { 20 | ErrNum int // 错误的数量 21 | } 22 | 23 | // CommentLine 当行的注释信息 24 | type CommentLine struct { 25 | Str string // 当行的注释内容 26 | Line int // 第一个注释内容,出现的行号 27 | Col int // 第一个注释内容,出现的列号 28 | } 29 | 30 | // CommentInfo 单个注释片段信息,包含多行的注释信息 31 | type CommentInfo struct { 32 | LineVec []CommentLine // 多行的内容存储 33 | ShortFlag bool // 是否是短注释,true表示短注释 34 | HeadFlag bool // 是否为头部注释, 例如一行中 --这样开头的就为头部注释 35 | } 36 | 37 | // GetRangeLoc 获取两个位置的范围,为[] 38 | func GetRangeLoc(beginLoc, endLoc *Location) Location { 39 | return Location{ 40 | StartLine: beginLoc.StartLine, 41 | StartColumn: beginLoc.StartColumn, 42 | EndLine: endLoc.EndLine, 43 | EndColumn: endLoc.EndColumn, 44 | } 45 | } 46 | 47 | // GetRangeLocExcludeEnd 获取两个位置的范围,第二个位置不算,为[) 48 | func GetRangeLocExcludeEnd(beginLoc, endLoc *Location) Location { 49 | return Location{ 50 | StartLine: beginLoc.StartLine, 51 | StartColumn: beginLoc.StartColumn, 52 | EndLine: endLoc.StartLine, 53 | EndColumn: endLoc.StartColumn, 54 | } 55 | } 56 | 57 | // CompareTwoLoc 对比两个loc是否一样的 58 | func CompareTwoLoc(oneLoc, twoLoc *Location) bool { 59 | if oneLoc.StartLine != twoLoc.StartLine { 60 | return false 61 | } 62 | 63 | if oneLoc.EndLine != twoLoc.EndLine { 64 | return false 65 | } 66 | 67 | if oneLoc.StartColumn != twoLoc.StartColumn { 68 | return false 69 | } 70 | 71 | if oneLoc.EndColumn != twoLoc.EndColumn { 72 | return false 73 | } 74 | 75 | return true 76 | } 77 | 78 | // IsInitialLoc 判断位置信息是否为初始的 79 | func (loc *Location) IsInitialLoc() bool { 80 | if loc.StartLine == 0 && loc.StartColumn == 0 && loc.EndLine == 0 && loc.EndColumn == 0 { 81 | return true 82 | } 83 | 84 | return false 85 | } 86 | 87 | // IsInLocStruct 判断传入的位置,是否在范围之内 88 | func (loc *Location) IsInLocStruct(posLine int, posCh int) bool { 89 | if posLine < loc.StartLine { 90 | return false 91 | } 92 | 93 | if posLine > loc.EndLine { 94 | return false 95 | } 96 | 97 | if posLine == loc.StartLine && posCh < loc.StartColumn { 98 | return false 99 | } 100 | 101 | if posLine == loc.EndLine && posCh > loc.EndColumn { 102 | return false 103 | } 104 | 105 | return true 106 | } 107 | 108 | // IsContainLoc 判断当前 loc是否 包含传入的loc 109 | func (loc Location) IsContainLoc(locOne Location) bool { 110 | if loc.StartLine > locOne.StartLine || loc.EndLine < locOne.EndLine { 111 | return false 112 | } 113 | 114 | if loc.StartLine == locOne.StartLine && loc.StartColumn > locOne.StartColumn { 115 | return false 116 | } 117 | 118 | if loc.EndLine == locOne.EndLine && loc.EndColumn < locOne.EndColumn { 119 | return false 120 | } 121 | 122 | return true 123 | } 124 | 125 | // IsBeforeLoc 判断当前 loc是否 在传入的loc之前 126 | func (loc Location) IsBeforeLoc(locOne Location) bool { 127 | if loc.StartLine < locOne.StartLine { 128 | return true 129 | } 130 | 131 | if loc.StartLine == locOne.StartLine && loc.StartColumn <= locOne.StartColumn { 132 | return true 133 | } 134 | 135 | return false 136 | } 137 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/compiler/parser/parse_block.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "luahelper-lsp/langserver/check/compiler/ast" 5 | "luahelper-lsp/langserver/check/compiler/lexer" 6 | ) 7 | 8 | // block ::= {stat} [retstat] 9 | func (p *Parser) parseBlock() *ast.Block { 10 | return &ast.Block{ 11 | Stats: p.parseStats(), 12 | RetExps: p.parseRetExps(), 13 | } 14 | } 15 | 16 | func (p *Parser) parseStats() []ast.Stat { 17 | stats := make([]ast.Stat, 0, 1) 18 | for !isReturnOrBlockEnd(p.l.LookAheadKind()) { 19 | stat := p.parseStat() 20 | if _, ok := stat.(*ast.EmptyStat); !ok { 21 | stats = append(stats, stat) 22 | } 23 | } 24 | return stats 25 | } 26 | 27 | // retstat ::= return [explist] [‘;’] 28 | // explist ::= exp {‘,’ exp} 29 | func (p *Parser) parseRetExps() []ast.Exp { 30 | l := p.l 31 | if l.LookAheadKind() != lexer.TkKwReturn { 32 | return nil 33 | } 34 | 35 | l.NextToken() 36 | switch l.LookAheadKind() { 37 | case lexer.TkEOF, lexer.TkKwEnd, 38 | lexer.TkKwElse, lexer.TkKwElseif, lexer.TkKwUntil: 39 | return []ast.Exp{} 40 | case lexer.TkSepSemi: 41 | l.NextToken() 42 | return []ast.Exp{} 43 | default: 44 | exps := p.parseExpList() 45 | if l.LookAheadKind() == lexer.TkSepSemi { 46 | l.NextToken() 47 | } 48 | return exps 49 | } 50 | } 51 | 52 | func isReturnOrBlockEnd(tokenKind lexer.TkKind) bool { 53 | switch tokenKind { 54 | case lexer.TkKwReturn, lexer.TkEOF, lexer.TkKwEnd, 55 | lexer.TkKwElse, lexer.TkKwElseif, lexer.TkKwUntil: 56 | return true 57 | } 58 | return false 59 | } 60 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/compiler/parser/parser.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "fmt" 5 | "luahelper-lsp/langserver/check/compiler/ast" 6 | "luahelper-lsp/langserver/check/compiler/lexer" 7 | ) 8 | 9 | // Parser 语法分析器,为把Lua源码文件解析成AST抽象语法树 10 | type Parser struct { 11 | // 词法分析器对象 12 | l *lexer.Lexer 13 | 14 | parseErrs []lexer.ParseError 15 | } 16 | 17 | // CreateParser 创建一个分析对象 18 | func CreateParser(chunk []byte, chunkName string) *Parser { 19 | parser := &Parser{} 20 | errHandler := parser.insertErr 21 | parser.l = lexer.NewLexer(chunk, chunkName) 22 | parser.l.SetErrHandler(errHandler) 23 | 24 | return parser 25 | } 26 | 27 | // BeginAnalyze 开始分析 28 | func (p *Parser) BeginAnalyze() (block *ast.Block, commentMap map[int]*lexer.CommentInfo, errList []lexer.ParseError) { 29 | defer func() { 30 | if err1 := recover(); err1 != nil { 31 | block = &ast.Block{} 32 | commentMap = p.l.GetCommentMap() 33 | errList = p.parseErrs 34 | return 35 | } 36 | }() 37 | 38 | p.l.SkipFirstLineComment() 39 | 40 | blockBeginLoc := p.l.GetHeardTokenLoc() 41 | block = p.parseBlock() // block 42 | blockEndLoc := p.l.GetNowTokenLoc() 43 | block.Loc = lexer.GetRangeLoc(&blockBeginLoc, &blockEndLoc) 44 | 45 | p.l.NextTokenKind(lexer.TkEOF) 46 | p.l.SetEnd() 47 | return block, p.l.GetCommentMap(), p.parseErrs 48 | } 49 | 50 | // BeginAnalyzeExp ParseExp single exp 51 | func (p *Parser) BeginAnalyzeExp() (exp ast.Exp) { 52 | defer func() { 53 | if err2 := recover(); err2 != nil { 54 | exp = nil 55 | } 56 | }() 57 | 58 | exp = p.parseSubExp(0) 59 | return exp 60 | } 61 | 62 | // GetErrList get parse error list 63 | func (p *Parser) GetErrList() (errList []lexer.ParseError) { 64 | return p.parseErrs 65 | } 66 | 67 | // insert now token info 68 | func (p *Parser) insertParserErr(loc lexer.Location, f string, a ...interface{}) { 69 | err := fmt.Sprintf(f, a...) 70 | paseError := lexer.ParseError{ 71 | ErrStr: err, 72 | Loc: loc, 73 | ReadFileErr: false, 74 | } 75 | 76 | p.insertErr(paseError) 77 | } 78 | 79 | func (p *Parser) insertErr(oneErr lexer.ParseError) { 80 | if len(p.parseErrs) < 30 { 81 | p.parseErrs = append(p.parseErrs, oneErr) 82 | } else { 83 | oneErr.ErrStr = oneErr.ErrStr + "(too many err...)" 84 | p.parseErrs = append(p.parseErrs, oneErr) 85 | manyError := &lexer.TooManyErr{ 86 | ErrNum: 30, 87 | } 88 | 89 | panic(manyError) 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/projects/projects.go: -------------------------------------------------------------------------------- 1 | package projects 2 | 3 | import ( 4 | "luahelper-lsp/langserver/check/annotation/annotateast" 5 | "luahelper-lsp/langserver/check/common" 6 | "luahelper-lsp/langserver/check/results" 7 | ) 8 | 9 | // 定义analysis访问check的接口 10 | 11 | // Projects 接口 12 | type Projects interface { 13 | // GetCacheFileStruct 获取第一阶段的文件结构,如果有cache,优先获取cache的内容,cache的会相对新 14 | GetCacheFileStruct(strFile string) (*results.FileStruct, bool) 15 | 16 | // 如果为自定义的引入其他lua文件的方式,获取真实的引入的子类型 17 | GetReferFrameType(referInfo *common.ReferInfo) (subReferType common.ReferFrameType) 18 | 19 | // getFirstFileStuct 获取第一阶段文件处理的结果 20 | GetFirstFileStuct(strFile string) (*results.FileStruct, bool) 21 | 22 | // getFirstReferFileResult 给一个引用关系,找第一阶段引用lua文件 23 | GetFirstReferFileResult(referInfo *common.ReferInfo) *results.FileResult 24 | 25 | // GetAllFilesMap 获取所有的文件map 26 | GetAllFilesMap() map[string]string 27 | 28 | // GetFileIndexInfo 获取文件的缓存结构 29 | GetFileIndexInfo() *common.FileIndexInfo 30 | 31 | // GetAllFilesPreStrMap 获取所有文件的前置路径map 32 | //GetAllFilesPreStrMap() map[string]string 33 | 34 | // GetFuncDefaultParamInfo 在函数注解中获取默认参数标记 35 | GetFuncDefaultParamInfo(fileName string, lastLine int, paramNameList []string) (paramDefaultNum int) 36 | 37 | IsMemberOfAnnotateClassByVar(strMemName string, strVarName string, varInfo *common.VarInfo) (isMember bool, className string) 38 | 39 | IsMemberOfAnnotateClassByLoc(strFile string, strFieldNamelist []string, lineForGetAnnotate int) (isMemberMap map[string]bool, className string) 40 | 41 | GetFieldAnnotateType(strFile string, lineForGetAnnotate int, retFieldTypeMap map[string][]string) 42 | 43 | // IsLineFragementEnum 获取当前行关联是否有enum注解类型 44 | IsLineFragementEnum(fileName string, startLine int) (isEnum bool) 45 | 46 | IsAnnotateTypeConst(name string, varInfo *common.VarInfo) (isConst bool) 47 | 48 | GetAnnotateTypeString(varInfo *common.VarInfo, varName string, keyName string, idx int) (retVec []string) 49 | 50 | GetFuncParamType(fileName string, lastLine int) (retMap map[string][]annotateast.Type) 51 | 52 | GetFuncParamTypeByClass(className string, funcName string) (retMap map[string][]string) 53 | GetFuncReturnTypeByClass(className string, funcName string) (retVec [][]string) 54 | 55 | GetFuncReturnInfo(fileName string, lastLine int) (paramInfo *common.FragementReturnInfo) 56 | 57 | GetFuncReturnType(fileName string, lastLine int) (retVec [][]annotateast.Type) 58 | 59 | GetFuncReturnTypeVec(fileName string, lastLine int) (retVec [][]string) 60 | 61 | GetAnnClassInfo(className string) *common.CreateTypeInfo 62 | 63 | IsFieldOfClass(className string, fieldName string) bool 64 | 65 | GetVarAnnType(fileName string, lastLine int) (string, bool) 66 | } 67 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/check/results/color_result.go: -------------------------------------------------------------------------------- 1 | package results 2 | 3 | import ( 4 | "luahelper-lsp/langserver/check/common" 5 | "luahelper-lsp/langserver/check/compiler/lexer" 6 | ) 7 | 8 | // ColorFileResult 第5阶段,分析单个文件,获取全局变量着色的功能 9 | type ColorFileResult struct { 10 | StrFile string // 文件的名称 11 | FileResult *FileResult // 单个文件分析的指针 12 | ColorResult map[common.ColorType]*common.OneColorResut // 保存找到的文件中,所有的颜色数据 13 | } 14 | 15 | // CreateColorFileInfo 创建第五阶段的文件分析指针 16 | func CreateColorFileInfo(strFile string) *ColorFileResult { 17 | return &ColorFileResult{ 18 | StrFile: strFile, 19 | FileResult: nil, 20 | ColorResult: map[common.ColorType]*common.OneColorResut{}, 21 | } 22 | } 23 | 24 | // InsertOneColorElem 插入一个找到的全局信息 25 | func (c *ColorFileResult) InsertOneColorElem(color common.ColorType, loc *lexer.Location) { 26 | // 如果是第二轮工程的check,_G的全局符号放入到工程的结构中 27 | oneColor := c.ColorResult[color] 28 | if oneColor == nil { 29 | oneColor := &common.OneColorResut{ 30 | LocVec: make([]lexer.Location, 0, 1), 31 | } 32 | oneColor.LocVec = append(oneColor.LocVec, *loc) 33 | c.ColorResult[color] = oneColor 34 | } else { 35 | oneColor.LocVec = append(oneColor.LocVec, *loc) 36 | } 37 | } 38 | 39 | // 插入一个全局变量,进行判断 40 | func (color *ColorFileResult) InsertOneGlobalColor(varInfo *common.VarInfo, loc *lexer.Location) { 41 | if varInfo == nil { 42 | return 43 | } 44 | 45 | if varInfo.ReferFunc != nil { 46 | color.InsertOneColorElem(common.CTGlobalFunc, loc) 47 | } else { 48 | color.InsertOneColorElem(common.CTGlobalVar, loc) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/codingconv/codingconv.go: -------------------------------------------------------------------------------- 1 | package codingconv 2 | 3 | import ( 4 | "luahelper-lsp/langserver/strbytesconv" 5 | 6 | "golang.org/x/text/encoding/simplifiedchinese" 7 | ) 8 | 9 | // ConvertStrToUtf8 GBK change to utf8 10 | func ConvertStrToUtf8(str string) string { 11 | if str == "" { 12 | return str 13 | } 14 | 15 | if isUtf8(strbytesconv.StringToBytes(str)) { 16 | return str 17 | } 18 | 19 | ret, ok := simplifiedchinese.GBK.NewDecoder().String(str) 20 | if ok != nil { 21 | return str 22 | } 23 | 24 | return ret 25 | } 26 | 27 | func preNUm(data byte) int { 28 | var i int = 0 29 | for data > 0 { 30 | if data%2 == 0 { 31 | i = 0 32 | } else { 33 | i++ 34 | } 35 | data /= 2 36 | } 37 | 38 | return i 39 | } 40 | 41 | func isUtf8(data []byte) bool { 42 | for i := 0; i < len(data); { 43 | if data[i]&0x80 == 0x00 { 44 | // 0XXX_XXXX 45 | i++ 46 | continue 47 | } else if num := preNUm(data[i]); num > 2 { 48 | // 110X_XXXX 10XX_XXXX 49 | // 1110_XXXX 10XX_XXXX 10XX_XXXX 50 | // 1111_0XXX 10XX_XXXX 10XX_XXXX 10XX_XXXX 51 | // 1111_10XX 10XX_XXXX 10XX_XXXX 10XX_XXXX 10XX_XXXX 52 | // 1111_110X 10XX_XXXX 10XX_XXXX 10XX_XXXX 10XX_XXXX 10XX_XXXX 53 | // preNUm() 返回首个字节的8个bits中首个0bit前面1bit的个数,该数量也是该字符所使用的字节数 54 | i++ 55 | for j := 0; j < num-1; j++ { 56 | if i >= len(data) { 57 | return false 58 | } 59 | 60 | //判断后面的 num - 1 个字节是不是都是10开头 61 | if data[i]&0xc0 != 0x80 { 62 | return false 63 | } 64 | i++ 65 | } 66 | } else { 67 | //其他情况说明不是utf-8 68 | return false 69 | } 70 | } 71 | return true 72 | } 73 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/codingconv/condingconv_test.go: -------------------------------------------------------------------------------- 1 | package codingconv 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | ) 7 | 8 | func TestComplete1(t *testing.T) { 9 | var data byte = 0 10 | for data = 0; data < 255; data++ { 11 | if getSprintfNum(data) != getCalcNum(data) { 12 | t.Fatalf("getCalcNum err, %d", data) 13 | } else { 14 | t.Logf("equal data=%d", data) 15 | } 16 | } 17 | 18 | if getSprintfNum(255) != getCalcNum(255) { 19 | t.Fatalf("getCalcNum err, %d", 255) 20 | } 21 | 22 | t.Logf("ok") 23 | } 24 | 25 | func getSprintfNum(data byte) int { 26 | str := fmt.Sprintf("%b", data) 27 | var i int = 0 28 | for i < len(str) { 29 | if str[i] != '1' { 30 | break 31 | } 32 | i++ 33 | } 34 | return i 35 | } 36 | 37 | func getCalcNum(data byte) int { 38 | var i int = 0 39 | for data > 0 { 40 | if data%2 == 0 { 41 | i = 0 42 | } else { 43 | i++ 44 | } 45 | data /= 2 46 | } 47 | 48 | return i 49 | } 50 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/filefolder/filefolder.go: -------------------------------------------------------------------------------- 1 | package filefolder 2 | 3 | import "os" 4 | 5 | // IsDirExist 判断所给文件夹是否存在 6 | func IsDirExist(path string) bool { 7 | s, err := os.Stat(path) 8 | if err != nil { 9 | return false 10 | } 11 | 12 | return s.IsDir() 13 | } 14 | 15 | // IsFileExist 判断所给文件夹是否存在 16 | func IsFileExist(path string) bool { 17 | s, err := os.Stat(path) 18 | if err != nil { 19 | return false 20 | } 21 | 22 | return !s.IsDir() 23 | } 24 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/get_online_req.go: -------------------------------------------------------------------------------- 1 | package langserver 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "net" 7 | "time" 8 | 9 | "luahelper-lsp/langserver/log" 10 | ) 11 | 12 | // 客户端获取当前查找在线人数,查找会去中心服上查询所有在线人数 13 | 14 | // GetOnlineParams 全局颜色配置 15 | type GetOnlineParams struct { 16 | Req int `json:"Req"` // 参数无意义 17 | } 18 | 19 | // GetOnlineReturn 在线的返回 20 | type GetOnlineReturn struct { 21 | Num int `json:"Num"` // 所有在线的人数 22 | } 23 | 24 | // 插件在线人数 25 | var onlinePeopleNum int = 0 26 | 27 | // GetOnlineReq 获取当前所有在线人数的接口 28 | func (l *LspServer) GetOnlineReq(ctx context.Context, vs GetOnlineParams) (onlineReturn GetOnlineReturn, err error) { 29 | log.Debug("GetOnlineReq num=%d", onlinePeopleNum) 30 | onlineReturn.Num = onlinePeopleNum 31 | return 32 | } 33 | 34 | // UDPReportOnline 上报协程 35 | func (l *LspServer) UDPReportOnline() { 36 | log.Debug("UDPReportOnline \n") 37 | conn, err := net.Dial("udp", "42.194.136.76:7778") //打开监听端口 38 | if err != nil { 39 | log.Error("conn fail...") 40 | return 41 | } 42 | 43 | defer conn.Close() 44 | log.Debug("client connect server successed \n") 45 | 46 | //创建协程,收取udp的在线回包数据 47 | go handleRecv(conn) 48 | 49 | l.SetReportOtherInfo() 50 | 51 | for { 52 | if l.enableReport { 53 | user := l.GetOnlineReportData() 54 | info, err := json.Marshal(user) 55 | if err != nil { 56 | log.Error("report Data err=%s", err.Error()) 57 | } else { 58 | conn.Write(info) 59 | } 60 | l.SetFirstReportFlag(0) 61 | } 62 | 63 | // 每120秒上报一次 64 | time.Sleep(time.Second * 120) 65 | } 66 | } 67 | 68 | // 处理udp的回包,获取在线人数 69 | func handleRecv(conn net.Conn) { 70 | var reportReturn OnlineReportReturn 71 | data := make([]byte, 2048) 72 | for { 73 | msgRead, err := conn.Read(data) //将读取的字节流赋值给msg_read和err 74 | if msgRead == 0 || err != nil { //如果字节流为0或者有错误 75 | continue 76 | } 77 | 78 | err1 := json.Unmarshal(data[0:msgRead], &reportReturn) 79 | if err1 != nil { 80 | log.Debug("handleRecv error:%s", err1.Error()) 81 | } else { 82 | log.Debug("handleRecv ok, num=%d", reportReturn.Num) 83 | onlinePeopleNum = reportReturn.Num 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/log/log.go: -------------------------------------------------------------------------------- 1 | package log 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "log" 7 | "os" 8 | ) 9 | 10 | var ( 11 | debugLog *log.Logger 12 | errorLog *log.Logger 13 | LspLog *log.Logger 14 | ) 15 | 16 | type logger = func(string, ...interface{}) 17 | 18 | var GFileLog *os.File = nil 19 | 20 | // logFlag 为true表示开启日志 21 | func InitLog(logFlag bool) { 22 | if !logFlag { 23 | debugLog = nil 24 | errorLog = nil 25 | LspLog = nil 26 | log.SetFlags(0) 27 | return 28 | } 29 | 30 | log.SetFlags(log.Ldate | log.Lmicroseconds | log.Llongfile) 31 | fileLog, err := os.OpenFile("log.txt", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666) 32 | 33 | if err != nil { 34 | log.Fatalln("failed to open log file:", err) 35 | return 36 | } 37 | 38 | debugLog = log.New(io.MultiWriter(fileLog), "Debug ", log.Ldate|log.Lmicroseconds|log.Lshortfile) 39 | errorLog = log.New(io.MultiWriter(fileLog), "Error ", log.Ldate|log.Lmicroseconds|log.Lshortfile) 40 | 41 | LspLog = debugLog 42 | GFileLog = fileLog 43 | } 44 | 45 | // 是否关闭日志 46 | func CloseLog() { 47 | if GFileLog != nil { 48 | GFileLog.Close() 49 | } 50 | } 51 | 52 | func Debug(format string, v ...interface{}) { 53 | if debugLog == nil { 54 | return 55 | } 56 | 57 | debugLog.Output(2, fmt.Sprintf(format, v...)) 58 | } 59 | 60 | func Error(format string, v ...interface{}) { 61 | if errorLog == nil { 62 | return 63 | } 64 | 65 | errorLog.Output(2, fmt.Sprintf(format, v...)) 66 | } 67 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/lsp_cmd_run.go: -------------------------------------------------------------------------------- 1 | package langserver 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | 7 | "luahelper-lsp/langserver/check/common" 8 | "luahelper-lsp/langserver/log" 9 | "luahelper-lsp/langserver/pathpre" 10 | ) 11 | 12 | // RunLocalDiagnostices 运行本地模式,校验错误 13 | func (l *LspServer) RunLocalDiagnostices(localpath string) { 14 | RootPath := "file://" + localpath 15 | RootURI := localpath 16 | 17 | pathpre.InitialRootURIAndPath(string(RootURI), string(RootPath)) 18 | 19 | log.Debug("Initialize ..., rootDir=%s, rooturl=%s", RootPath, RootURI) 20 | 21 | vscodeRoot := pathpre.VscodeURIToString(string(RootURI)) 22 | dirManager := common.GConfig.GetDirManager() 23 | dirManager.SetVSRootDir(vscodeRoot) 24 | 25 | initOptions := &InitializationOptions{ 26 | AllEnable: true, 27 | } 28 | 29 | // 按顺序插入 30 | checkFlagList := getCheckFlagList(initOptions) 31 | 32 | ctx := context.Background() 33 | 34 | initErr := l.initialCheckProject(ctx, checkFlagList, "local", 0, nil, true, nil, nil) 35 | if initErr != nil { 36 | log.Error("initial luahelper err: " + initErr.Error()) 37 | return 38 | } 39 | log.Debug("initial luahelper ok") 40 | project := l.getAllProject() 41 | if project == nil { 42 | log.Error("CheckProject is nil") 43 | return 44 | } 45 | 46 | fileErrorMap := project.GetAllFileErrorInfo() 47 | 48 | // 保存全局的错误诊断信息 49 | l.fileErrorMap = fileErrorMap 50 | if len(fileErrorMap) == 0 { 51 | log.Debug("GetAllFileErrorInfo is empty..") 52 | return 53 | } 54 | 55 | for file, info := range fileErrorMap { 56 | for _, errinfo := range info { 57 | fmt.Printf("%v, line=%v, errType=%v, errStr=%s\n", file, errinfo.Loc.StartLine, (int)(errinfo.ErrType), 58 | errinfo.ErrStr) 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/lspcommon/util.go: -------------------------------------------------------------------------------- 1 | package lspcommon 2 | 3 | import ( 4 | "fmt" 5 | "luahelper-lsp/langserver/check/common" 6 | "luahelper-lsp/langserver/check/compiler/lexer" 7 | 8 | "luahelper-lsp/langserver/pathpre" 9 | lsp "luahelper-lsp/langserver/protocol" 10 | ) 11 | 12 | // LocToRange luacheck里面的LocStruct转换为Range结构 13 | func LocToRange(loc *lexer.Location) lsp.Range { 14 | return lsp.Range{ 15 | Start: lsp.Position{ 16 | Line: uint32(loc.StartLine) - 1, 17 | Character: uint32(loc.StartColumn), 18 | }, 19 | End: lsp.Position{ 20 | Line: uint32(loc.EndLine) - 1, 21 | Character: (uint32)(loc.EndColumn), 22 | }, 23 | } 24 | } 25 | 26 | func IsSameErrList(oldErrList []common.CheckError, newErrList []common.CheckError) bool { 27 | oldLen := len(oldErrList) 28 | newLen := len(newErrList) 29 | if oldLen != newLen { 30 | // 如果长度不相等,肯定不一致 31 | return false 32 | } 33 | 34 | for i := 0; i < oldLen; i++ { 35 | oldOne := oldErrList[i] 36 | newOne := newErrList[i] 37 | 38 | if oldOne.ToString() != newOne.ToString() { 39 | return false 40 | } 41 | } 42 | 43 | return true 44 | } 45 | 46 | // 获取文件名转换为的DocumentURI路径 47 | func GetFileDocumentURI(strFile string) lsp.DocumentURI { 48 | return lsp.DocumentURI(pathpre.StringToVscodeURI(strFile)) 49 | } 50 | 51 | // OffsetForPosition Previously used bytes converted to rune. 52 | // Now use the high bit to determine how many bits the character occupies. 53 | // posLine (zero-based, from 0) 54 | func OffsetForPosition(contents []byte, posLine, posCh int) (int, error) { 55 | line := 0 56 | col := 0 57 | offset := 0 58 | 59 | getCharBytes := func(b byte) int { 60 | num := 0 61 | for b&(1< posCh) || line > posLine { 73 | return 0, fmt.Errorf("character %d (zero-based) is beyond line %d boundary (zero-based)", posCh, posLine) 74 | } 75 | 76 | curChar := contents[index] 77 | if curChar > 127 { 78 | curCharBytes := getCharBytes(curChar) 79 | index += curCharBytes - 1 80 | offset += curCharBytes - 1 81 | } 82 | offset++ 83 | if curChar == '\n' { 84 | line++ 85 | col = 0 86 | } else { 87 | col++ 88 | } 89 | 90 | } 91 | if line == posLine && col == posCh { 92 | return offset, nil 93 | } 94 | if line == 0 { 95 | return 0, fmt.Errorf("character %d (zero-based) is beyond first line boundary", posCh) 96 | } 97 | return 0, fmt.Errorf("file only has %d lines", line+1) 98 | } 99 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/lsptest.go: -------------------------------------------------------------------------------- 1 | package langserver 2 | 3 | import ( 4 | "context" 5 | "luahelper-lsp/langserver/check/common" 6 | lsp "luahelper-lsp/langserver/protocol" 7 | 8 | "github.com/yinfei8/jrpc2" 9 | "github.com/yinfei8/jrpc2/handler" 10 | ) 11 | 12 | func createLspTest(strRootPath string, strRootUri string) *LspServer{ 13 | common.GlobalConfigDefautInit() 14 | common.GConfig.IntialGlobalVar() 15 | 16 | lspServer := CreateLspServer() 17 | lspServer.server = jrpc2.NewServer(handler.Map{}, &jrpc2.ServerOptions{ 18 | AllowPush: false, 19 | Concurrency: 1, 20 | }) 21 | 22 | context := context.Background() 23 | initializeParams := InitializeParams{ 24 | InitializeParams : lsp.InitializeParams { 25 | InnerInitializeParams : lsp.InnerInitializeParams{ 26 | RootPath : strRootPath, 27 | RootURI: lsp.DocumentURI(strRootUri), 28 | }, 29 | }, 30 | } 31 | lspServer.Initialize(context, initializeParams) 32 | return lspServer 33 | } 34 | 35 | func createLspTestWithPlugin(strRootPath string, strRootUri string, pluginPath string) *LspServer{ 36 | common.GlobalConfigDefautInit() 37 | common.GConfig.IntialGlobalVar() 38 | 39 | lspServer := CreateLspServer() 40 | lspServer.server = jrpc2.NewServer(handler.Map{}, &jrpc2.ServerOptions{ 41 | AllowPush: false, 42 | Concurrency: 1, 43 | }) 44 | 45 | context := context.Background() 46 | initializeParams := InitializeParams{ 47 | InitializeParams : lsp.InitializeParams { 48 | InnerInitializeParams : lsp.InnerInitializeParams{ 49 | RootPath : strRootPath, 50 | RootURI: lsp.DocumentURI(strRootUri), 51 | }, 52 | }, 53 | InitializationOptions: &InitializationOptions{ 54 | AllEnable: true, 55 | PluginPath: pluginPath, 56 | }, 57 | } 58 | lspServer.Initialize(context, initializeParams) 59 | return lspServer 60 | } 61 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/online_report.go: -------------------------------------------------------------------------------- 1 | package langserver 2 | 3 | import ( 4 | "runtime" 5 | ) 6 | 7 | // OnlineReport 向中心服务器,需要上报统计的信息 8 | type OnlineReport struct { 9 | ClientType string `json:"clientType"` // 客户端类型 10 | FileNumber int `json:"fileNumber"` // 工程lua文件的数量 11 | OsType string `json:"osType"` // 客户端操作系统类型 12 | ClientVer string `json:"clientVer"` // 客户端的版本号,例如0.2.1 13 | FirstReport int `json:"firstReport"` // 客户端是否首次打开插件上报, 1为是 14 | CostMsTime int `json:"costMsTime"` // 初次加载的耗时时间毫秒 15 | WorkspaceFolderNum int `json:"workspaceFolderNum"` // 用户多文件夹数 16 | } 17 | 18 | // OnlineReportReturn 中心服务的返回 19 | type OnlineReportReturn struct { 20 | Num int `json:"Num"` // 所有在线的人数 21 | } 22 | 23 | // SetOnlineReportParam 连接初始化时,同步客户端的类型,以及这个工程的所包含的lua文件数量 24 | func (l *LspServer) SetOnlineReportParam(clientType string, fileNumber int, costMsTime int, workspaceFolderNum int) { 25 | l.onlineReport.ClientType = clientType 26 | l.onlineReport.FileNumber = fileNumber 27 | l.onlineReport.CostMsTime = costMsTime 28 | l.onlineReport.WorkspaceFolderNum = workspaceFolderNum 29 | } 30 | 31 | // SetLuaFileNumber 更新工程lua文件的数量 32 | func (l *LspServer) SetLuaFileNumber(fileNumber int) { 33 | l.onlineReport.FileNumber = fileNumber 34 | } 35 | 36 | // GetOnlineReportData 获取向中心服统计的数据 37 | func (l *LspServer) GetOnlineReportData() OnlineReport { 38 | return l.onlineReport 39 | } 40 | 41 | // SetFirstReportFlag 设置是否第一次上报标记 42 | func (l *LspServer) SetFirstReportFlag(flag int) { 43 | l.onlineReport.FirstReport = flag 44 | } 45 | 46 | // SetReportOtherInfo 设置上报的其他信息 47 | func (l *LspServer) SetReportOtherInfo() { 48 | l.onlineReport.OsType = runtime.GOOS 49 | } -------------------------------------------------------------------------------- /luahelper-lsp/langserver/pathpre/pathpre.go: -------------------------------------------------------------------------------- 1 | package pathpre 2 | 3 | import ( 4 | "net/url" 5 | "strings" 6 | ) 7 | 8 | // preFixStr 工程项目的前缀,windows平台的前缀是 file:///, mac平台的前缀是file:// 9 | var preFixStr string = "file:///" 10 | 11 | // InitialRootURIAndPath 初始化前缀 12 | func InitialRootURIAndPath(rootURI, rootPath string) { 13 | rootURI, _ = url.QueryUnescape(rootURI) 14 | rootURI = strings.Replace(rootURI, "\\", "/", -1) 15 | 16 | rootPath, _ = url.QueryUnescape(rootPath) 17 | rootPath = strings.Replace(rootPath, "\\", "/", -1) 18 | 19 | if len(rootURI) < 8 { 20 | return 21 | } 22 | 23 | subRootURI := rootURI[7:] 24 | if subRootURI == rootPath { 25 | preFixStr = "file://" 26 | } 27 | } 28 | 29 | // GetRemovePreStr 如果字符串以 ./为前缀,去除掉前缀 30 | func GetRemovePreStr(str string) string { 31 | if strings.HasPrefix(str, "./") { 32 | str = str[2:] 33 | } 34 | 35 | return str 36 | } 37 | 38 | // VscodeURIToString 插件传入的路径转换 39 | // vscode 传来的路径: file:///g%3A/luaproject 40 | // 统一转换为:g%3A/luaproject,去掉前缀的file:///,并且都是这样的/../ 41 | func VscodeURIToString(strURL string) string { 42 | fileURL := strings.Replace(strURL, preFixStr, "", 1) 43 | fileURL, _ = url.QueryUnescape(fileURL) 44 | fileURL = strings.Replace(string(fileURL), "\\", "/", -1) 45 | 46 | return fileURL 47 | } 48 | 49 | // StringToVscodeURI 文件真实路径转换成类似的 file:///g%3A/luaproject/src/tutorial.lua" 50 | func StringToVscodeURI(strPath string) string { 51 | strPath = strings.Replace(string(strPath), "\\", "/", -1) 52 | strEncode := strPath 53 | strURI := preFixStr + strEncode 54 | return strURI 55 | } 56 | 57 | // GeConvertPathFormat 文件路径统一为 58 | func GeConvertPathFormat(strPath string) string { 59 | strDir := strings.Replace(string(strPath), "\\", "/", -1) 60 | return strDir 61 | } 62 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/progress_ntf.go: -------------------------------------------------------------------------------- 1 | package langserver 2 | 3 | import ( 4 | "context" 5 | "luahelper-lsp/langserver/log" 6 | ) 7 | 8 | // ProgressState 进度的状态 9 | type ProgressState int 10 | 11 | const ( 12 | // PSDirtory 加载目录 13 | PSDirtory ProgressState = 0 14 | // PSFile 加载文件中 15 | PSFile ProgressState = 1 16 | // PSFinish 加载完毕 17 | PSFinish ProgressState = 2 18 | ) 19 | 20 | // IProgressReport 插件后台给插件前端推送加载工程的进度状态 21 | type IProgressReport struct { 22 | State int `json:"State"` // 通知的状态,0为加载目录, 1为加载文件中,2为加载完毕 23 | Text string `json:"Text"` // 显示的字符串 24 | } 25 | 26 | // PushProgressReport 给客户端推送加载的进度消息 27 | func (l *LspServer)PushProgressReport(ctx context.Context, state int, strContent string) { 28 | err := l.server.Notify(ctx, "luahelper/progressReport", IProgressReport{ 29 | State: state, 30 | Text: strContent, 31 | }) 32 | 33 | if err != nil { 34 | log.Debug("PushProgressReport error=%v", err) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/push_client_message.go: -------------------------------------------------------------------------------- 1 | package langserver 2 | 3 | import ( 4 | "context" 5 | 6 | lsp "luahelper-lsp/langserver/protocol" 7 | 8 | "luahelper-lsp/langserver/log" 9 | ) 10 | 11 | // // PushShowMessage 给客户端推送提示消息 12 | // func PushShowMessage(ctx context.Context, messageType lsp.MessageType, strContent string) { 13 | // err := GLspGlobal.GServer.Notify(ctx, "window/showMessage", lsp.ShowMessageParams{ 14 | // Type: messageType, 15 | // Message: strContent, 16 | // }) 17 | 18 | // if err != nil { 19 | // log.Debug("PushShowMessage error=%v", err) 20 | // } 21 | // } 22 | 23 | // sendDiagnostics 给客户端推送错误诊断消息 24 | func (l *LspServer)sendDiagnostics(ctx context.Context, diagnostics lsp.PublishDiagnosticsParams) { 25 | err := l.server.Notify(ctx, "textDocument/publishDiagnostics", diagnostics) 26 | if err != nil { 27 | log.Debug("PushShowMessage error=%v", err) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/strbytesconv/strbytesconv.go: -------------------------------------------------------------------------------- 1 | package strbytesconv 2 | 3 | import ( 4 | "reflect" 5 | "unsafe" 6 | ) 7 | 8 | // StringToBytes 实现string 转换成 []byte, 不用额外的内存分配 9 | func StringToBytes(str string) (bytes []byte) { 10 | ss := *(*reflect.StringHeader)(unsafe.Pointer(&str)) 11 | bs := (*reflect.SliceHeader)(unsafe.Pointer(&bytes)) 12 | bs.Data = ss.Data 13 | bs.Len = ss.Len 14 | bs.Cap = ss.Len 15 | return bytes 16 | } 17 | 18 | // BytesToString 实现 []byte 转换成 string, 不需要额外的内存分配 19 | func BytesToString(bytes []byte) string { 20 | return *(*string)(unsafe.Pointer(&bytes)) 21 | } 22 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/strbytesconv/strbytesconv_test.go: -------------------------------------------------------------------------------- 1 | package strbytesconv 2 | 3 | import ( 4 | "reflect" 5 | "testing" 6 | ) 7 | 8 | func Test_StringToBytes(t *testing.T) { 9 | type args struct { 10 | str string 11 | } 12 | tests := []struct { 13 | name string 14 | args args 15 | wantBytes []byte 16 | }{ 17 | // TODO: Add test cases. 18 | { 19 | name: "testStrToBytes", 20 | args: args{ 21 | str: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 22 | }, 23 | wantBytes: []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 24 | }, 25 | } 26 | for _, tt := range tests { 27 | t.Run(tt.name, func(t *testing.T) { 28 | gotBytes := StringToBytes(tt.args.str) 29 | if !reflect.DeepEqual(gotBytes, tt.wantBytes) { 30 | t.Errorf("StringToBytes() = %v, want %v", gotBytes, tt.wantBytes) 31 | } 32 | t.Logf("gotBytes Pointer %p, tt.args.str Pointer %p", &gotBytes, &tt.args.str) 33 | }) 34 | } 35 | } 36 | 37 | func Test_BytesToString(t *testing.T) { 38 | type args struct { 39 | bytes []byte 40 | } 41 | tests := []struct { 42 | name string 43 | args args 44 | want string 45 | }{ 46 | // TODO: Add test cases. 47 | { 48 | name: "testBytesToStr", 49 | args: args{ 50 | bytes: []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 51 | }, 52 | want: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 53 | }, 54 | } 55 | for _, tt := range tests { 56 | t.Run(tt.name, func(t *testing.T) { 57 | got := BytesToString(tt.args.bytes) 58 | if got != tt.want { 59 | t.Errorf("BytesToString() = %v, want %v", got, tt.want) 60 | } 61 | t.Logf("gotStr Pointer %p, tt.args.bytes Pointer %p", &got, &tt.args.bytes) 62 | }) 63 | } 64 | } 65 | 66 | // go test -v -run=none -bench=. -benchmem=true 67 | // Benchmark_StringToBytes-8 1000000000 0.477 ns/op 0 B/op 0 allocs/op 68 | // Benchmark_getStringToBytes-8 20491503 58.0 ns/op 64 B/op 1 allocs/op 69 | // Benchmark_BytesToString-8 1000000000 0.473 ns/op 0 B/op 0 allocs/op 70 | // Benchmark_getBytesToString-8 22655529 49.1 ns/op 64 B/op 1 allocs/op 71 | var testStr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" 72 | var testBytes = []byte(testStr) 73 | 74 | func getBytesToString(bytes []byte) string { 75 | return string(bytes) 76 | } 77 | 78 | func getStringToBytes(str string) []byte { 79 | return []byte(str) 80 | } 81 | 82 | func Benchmark_StringToBytes(b *testing.B) { 83 | for i := 0; i < b.N; i++ { 84 | StringToBytes(testStr) 85 | } 86 | } 87 | 88 | func Benchmark_getStringToBytes(b *testing.B) { 89 | for i := 0; i < b.N; i++ { 90 | getStringToBytes(testStr) 91 | } 92 | } 93 | 94 | func Benchmark_BytesToString(b *testing.B) { 95 | for i := 0; i < b.N; i++ { 96 | BytesToString(testBytes) 97 | } 98 | } 99 | 100 | func Benchmark_getBytesToString(b *testing.B) { 101 | for i := 0; i < b.N; i++ { 102 | getBytesToString(testBytes) 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/textdocument_file_request_test.go: -------------------------------------------------------------------------------- 1 | package langserver 2 | 3 | import ( 4 | "context" 5 | "io/ioutil" 6 | lsp "luahelper-lsp/langserver/protocol" 7 | "path/filepath" 8 | "runtime" 9 | "testing" 10 | ) 11 | 12 | func TestProjectOpen(t *testing.T) { 13 | _, filename, _, _ := runtime.Caller(0) 14 | paths, _ := filepath.Split(filename) 15 | 16 | strRootPath := paths + "../testdata/project/test1" 17 | strRootPath, _ = filepath.Abs(strRootPath) 18 | 19 | strRootURI := "file://" + strRootPath 20 | lspServer := createLspTest(strRootPath, strRootURI) 21 | context := context.Background() 22 | 23 | fileName := strRootPath + "/" + "test1.lua" 24 | data, err := ioutil.ReadFile(fileName) 25 | 26 | if err != nil { 27 | t.Fatalf("read file:%s err=%s", fileName, err.Error()) 28 | } 29 | 30 | openParams := lsp.DidOpenTextDocumentParams{ 31 | TextDocument: lsp.TextDocumentItem{ 32 | URI: lsp.DocumentURI(fileName), 33 | Text: string(data), 34 | }, 35 | } 36 | err1 := lspServer.TextDocumentDidOpen(context, openParams) 37 | if err1 != nil { 38 | t.Fatalf("didopen file:%s err=%s", fileName, err1.Error()) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/textdocument_highlight.go: -------------------------------------------------------------------------------- 1 | package langserver 2 | 3 | import ( 4 | "context" 5 | "luahelper-lsp/langserver/check" 6 | "luahelper-lsp/langserver/check/common" 7 | "luahelper-lsp/langserver/log" 8 | "luahelper-lsp/langserver/lspcommon" 9 | lsp "luahelper-lsp/langserver/protocol" 10 | ) 11 | 12 | // TextDocumentHighlight 对变量单击选中着色 13 | func (l *LspServer) TextDocumentHighlight(ctx context.Context, vs lsp.TextDocumentPositionParams) (retVec []lsp.DocumentHighlight, 14 | err error) { 15 | l.requestMutex.Lock() 16 | defer l.requestMutex.Unlock() 17 | 18 | if !l.isCanHighlight() { 19 | log.Error("IsCanHighlight is false") 20 | return 21 | } 22 | 23 | comResult := l.beginFileRequest(vs.TextDocument.URI, vs.Position) 24 | if !comResult.result { 25 | return 26 | } 27 | 28 | if len(comResult.contents) == 0 || comResult.offset >= len(comResult.contents) { 29 | return 30 | } 31 | 32 | project := l.getAllProject() 33 | varStruct := check.GetVarStruct(comResult.contents, comResult.offset, comResult.pos.Line, comResult.pos.Character) 34 | if !varStruct.ValidFlag { 35 | log.Error("TextDocumentHighlight varStruct.ValidFlag not valid") 36 | return 37 | } 38 | 39 | // 去掉前缀后的名字 40 | referenVecs := project.FindReferences(comResult.strFile, &varStruct, common.CRSHighlight) 41 | retVec = make([]lsp.DocumentHighlight, 0, len(referenVecs)) 42 | for _, referVarInfo := range referenVecs { 43 | retVec = append(retVec, lsp.DocumentHighlight{ 44 | Range: lspcommon.LocToRange(&referVarInfo.Loc), 45 | Kind: lsp.Write, 46 | }) 47 | } 48 | return 49 | } 50 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/textdocument_references.go: -------------------------------------------------------------------------------- 1 | package langserver 2 | 3 | import ( 4 | "context" 5 | "luahelper-lsp/langserver/check" 6 | "luahelper-lsp/langserver/check/common" 7 | "luahelper-lsp/langserver/log" 8 | "luahelper-lsp/langserver/lspcommon" 9 | protocol "luahelper-lsp/langserver/protocol" 10 | ) 11 | 12 | // TextDocumentReferences 文件中查找符合的所有的引用 13 | func (l *LspServer) TextDocumentReferences(ctx context.Context, vs protocol.ReferenceParams) (locList []protocol.Location, err error) { 14 | comResult := l.beginFileRequest(vs.TextDocument.URI, vs.Position) 15 | if !comResult.result { 16 | return 17 | } 18 | 19 | if len(comResult.contents) == 0 || comResult.offset >= len(comResult.contents) { 20 | return 21 | } 22 | 23 | project := l.getAllProject() 24 | varStruct := check.GetVarStruct(comResult.contents, comResult.offset, comResult.pos.Line, comResult.pos.Character) 25 | if !varStruct.ValidFlag { 26 | log.Error("TextDocumentReferences not valid") 27 | return 28 | } 29 | 30 | // subCtx, cancel := context.WithTimeout(ctx, 1 * time.Second) 31 | // defer cancel() 32 | 33 | // time.Sleep(time.Second * 2) 34 | 35 | // select { 36 | // case <-subCtx.Done(): 37 | // fmt.Println("main", ctx.Err()) 38 | // default: 39 | // log.Error("not hit") 40 | // } 41 | 42 | // 去掉前缀后的名字 43 | referenVecs := project.FindReferences(comResult.strFile, &varStruct, common.CRSReference) 44 | locList = make([]protocol.Location, 0, len(referenVecs)) 45 | referenceNum := common.GConfig.ReferenceMaxNum 46 | for i, referVarInfo := range referenVecs { 47 | if i >= referenceNum { 48 | break 49 | } 50 | 51 | locList = append(locList, protocol.Location{ 52 | URI: lspcommon.GetFileDocumentURI(referVarInfo.StrFile), 53 | Range: lspcommon.LocToRange(&referVarInfo.Loc), 54 | }) 55 | } 56 | 57 | return locList, nil 58 | } 59 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/textdocument_rename.go: -------------------------------------------------------------------------------- 1 | package langserver 2 | 3 | import ( 4 | "context" 5 | "luahelper-lsp/langserver/check" 6 | "luahelper-lsp/langserver/check/common" 7 | "luahelper-lsp/langserver/log" 8 | "luahelper-lsp/langserver/lspcommon" 9 | lsp "luahelper-lsp/langserver/protocol" 10 | ) 11 | 12 | // TextDocumentRename 批量更改名字 13 | func (l *LspServer) TextDocumentRename(ctx context.Context, vs lsp.RenameParams) (edit lsp.WorkspaceEdit, err error) { 14 | // 判断打开的文件,是否是需要分析的文件 15 | comResult := l.beginFileRequest(vs.TextDocument.URI, vs.Position) 16 | if !comResult.result { 17 | return 18 | } 19 | 20 | if len(comResult.contents) == 0 || comResult.offset >= len(comResult.contents) { 21 | return 22 | } 23 | 24 | project := l.getAllProject() 25 | varStruct := check.GetVarStruct(comResult.contents, comResult.offset, comResult.pos.Line, comResult.pos.Character) 26 | if !varStruct.ValidFlag { 27 | log.Error("TextDocumentRename varStruct.ValidFlag not valid") 28 | return 29 | } 30 | 31 | // 去掉前缀后的名字 32 | referenVecs := project.FindReferences(comResult.strFile, &varStruct, common.CRSRename) 33 | edit.Changes = map[string][]lsp.TextEdit{} 34 | 35 | for _, referVarInfo := range referenVecs { 36 | retRange := lspcommon.LocToRange(&referVarInfo.Loc) 37 | uriStr := string(lspcommon.GetFileDocumentURI(referVarInfo.StrFile)) 38 | 39 | if _, ok := edit.Changes[uriStr]; !ok { 40 | edit.Changes[uriStr] = []lsp.TextEdit{} 41 | } 42 | 43 | edit.Changes[uriStr] = append(edit.Changes[uriStr], 44 | lsp.TextEdit{ 45 | Range: retRange, 46 | NewText: vs.NewName, 47 | }) 48 | } 49 | return 50 | } 51 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/textdocument_symbol.go: -------------------------------------------------------------------------------- 1 | package langserver 2 | 3 | import ( 4 | "context" 5 | "luahelper-lsp/langserver/check/common" 6 | "luahelper-lsp/langserver/log" 7 | "luahelper-lsp/langserver/lspcommon" 8 | "luahelper-lsp/langserver/pathpre" 9 | lsp "luahelper-lsp/langserver/protocol" 10 | ) 11 | 12 | // TextDocumentSymbol 提示文件中生成所有的符合 @使用 13 | func (l *LspServer)TextDocumentSymbol(ctx context.Context, vs lsp.DocumentSymbolParams) (itemsResult []lsp.DocumentSymbol, err error) { 14 | strFile := pathpre.VscodeURIToString(string(vs.TextDocument.URI)) 15 | project := l.getAllProject() 16 | if !project.IsNeedHandle(strFile) { 17 | log.Debug("not need to handle strFile=%s", strFile) 18 | return 19 | } 20 | 21 | // 文件截断后的名字 22 | fileSymbolVec := project.FindFileAllSymbol(strFile) 23 | 24 | // 将filesymbols 转换为 lsp document 25 | itemsResult = transferSymbolVec(fileSymbolVec) 26 | return 27 | } 28 | 29 | // transferSymbolVec 转换fileSybmols为DocumentSymbol 30 | func transferSymbolVec(fileSymbolVec []common.FileSymbolStruct) (items []lsp.DocumentSymbol) { 31 | vecLen := len(fileSymbolVec) 32 | items = make([]lsp.DocumentSymbol, 0, vecLen) 33 | 34 | for _, oneSymbol := range fileSymbolVec { 35 | ra := lspcommon.LocToRange(&oneSymbol.Loc) 36 | 37 | fullName := oneSymbol.Name 38 | if oneSymbol.ContainerName != "" { 39 | if oneSymbol.ContainerName == "local" { 40 | fullName = oneSymbol.ContainerName + " " + fullName 41 | } else { 42 | fullName = oneSymbol.ContainerName + "." + fullName 43 | } 44 | } 45 | 46 | symbol := lsp.DocumentSymbol{ 47 | Name: fullName, 48 | Kind: lsp.Variable, 49 | Range: ra, 50 | SelectionRange: ra, 51 | } 52 | 53 | if oneSymbol.Children != nil { 54 | symbol.Children = transferSymbolVec(oneSymbol.Children) 55 | } 56 | if oneSymbol.Kind == common.IKAnnotateAlias { 57 | symbol.Kind = lsp.Interface 58 | symbol.Detail = "annotate alias" 59 | } else if oneSymbol.Kind == common.IKAnnotateClass { 60 | symbol.Kind = lsp.Interface 61 | symbol.Detail = "annotate class" 62 | } else if oneSymbol.Kind == common.IKFunction { 63 | symbol.Kind = lsp.Function 64 | symbol.Detail = "function" 65 | } else if len(oneSymbol.Children) != 0 { 66 | symbol.Kind = lsp.Class 67 | symbol.Detail = "table" 68 | } else { 69 | symbol.Detail = "variable" 70 | } 71 | 72 | items = append(items, symbol) 73 | } 74 | return 75 | } 76 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/textdocument_varColor.go: -------------------------------------------------------------------------------- 1 | package langserver 2 | 3 | import ( 4 | "context" 5 | "luahelper-lsp/langserver/log" 6 | "luahelper-lsp/langserver/lspcommon" 7 | "luahelper-lsp/langserver/pathpre" 8 | lsp "luahelper-lsp/langserver/protocol" 9 | ) 10 | 11 | // GetColorParams 全局颜色配置 12 | type GetColorParams struct { 13 | Uri string `json:"uri"` 14 | } 15 | 16 | // IAnnotator 单个颜色 17 | type IAnnotator struct { 18 | Uri string `json:"uri"` 19 | Ranges []lsp.Range `json:"ranges"` 20 | AnnotatorType int `json:"annotatorType"` 21 | } 22 | 23 | // TextDocumentGetVarColor 获取文档中变量的颜色 24 | func (l *LspServer)TextDocumentGetVarColor(ctx context.Context, vs GetColorParams) (annolist []IAnnotator, err error) { 25 | project := l.getAllProject() 26 | 27 | // 判断打开的文件,是否是需要分析的文件 28 | strFile := pathpre.VscodeURIToString(string(vs.Uri)) 29 | if !project.IsNeedHandle(strFile) { 30 | log.Debug("not need to handle strFile=%s", strFile) 31 | return 32 | } 33 | 34 | colorResult := project.FindAllColorVar(strFile) 35 | allLen := 0 36 | for _, oneColor := range colorResult { 37 | allLen = allLen + len(oneColor.LocVec) 38 | } 39 | 40 | annolist = make([]IAnnotator, 0, allLen) 41 | for colorType, oneColor := range colorResult { 42 | oneAnno := IAnnotator{ 43 | Uri: vs.Uri, 44 | AnnotatorType: (int)(colorType), 45 | } 46 | 47 | for _, oneLoc := range oneColor.LocVec { 48 | oneRange := lspcommon.LocToRange(&oneLoc) 49 | oneAnno.Ranges = append(oneAnno.Ranges, oneRange) 50 | } 51 | annolist = append(annolist, oneAnno) 52 | } 53 | 54 | return 55 | } 56 | 57 | func (l *LspServer)TextDocumentColor(ctx context.Context,colorParams lsp.DocumentColorParams) (colorList []lsp.ColorInformation,err error) { 58 | log.Debug("not need to handle strFile=%s", colorParams.TextDocument.URI) 59 | 60 | project := l.getAllProject() 61 | 62 | // 判断打开的文件,是否是需要分析的文件 63 | strFile := pathpre.VscodeURIToString(string(colorParams.TextDocument.URI)) 64 | if !project.IsNeedHandle(strFile) { 65 | log.Debug("not need to handle strFile=%s", strFile) 66 | return 67 | } 68 | 69 | colorResult := project.FindAllColorVar(strFile) 70 | allLen := 0 71 | for _, oneColor := range colorResult { 72 | allLen = allLen + len(oneColor.LocVec) 73 | } 74 | 75 | colorList = make([]lsp.ColorInformation, 0, allLen) 76 | for _, oneColor := range colorResult { 77 | for _, oneLoc := range oneColor.LocVec { 78 | oneAnno := lsp.ColorInformation{ 79 | Range: lspcommon.LocToRange(&oneLoc), 80 | Color: lsp.Color { 81 | Red:0.5, 82 | Green:0.5, 83 | Blue:0.5, 84 | }, 85 | } 86 | colorList = append(colorList, oneAnno) 87 | } 88 | } 89 | 90 | return colorList, err 91 | } -------------------------------------------------------------------------------- /luahelper-lsp/langserver/workspace_folders.go: -------------------------------------------------------------------------------- 1 | package langserver 2 | 3 | import ( 4 | "context" 5 | 6 | "luahelper-lsp/langserver/check" 7 | "luahelper-lsp/langserver/check/common" 8 | 9 | "luahelper-lsp/langserver/log" 10 | "luahelper-lsp/langserver/pathpre" 11 | lsp "luahelper-lsp/langserver/protocol" 12 | ) 13 | 14 | // WorkspaceChangeWorkspaceFolders 文件夹有变化 15 | func (l *LspServer)WorkspaceChangeWorkspaceFolders(ctx context.Context, params lsp.DidChangeWorkspaceFoldersParams) error { 16 | for _, oneFolder := range params.Event.Added { 17 | folderPath := pathpre.VscodeURIToString(oneFolder.URI) 18 | l.addWorkspaceFolder(ctx, folderPath) 19 | } 20 | 21 | for _, oneFolder := range params.Event.Removed { 22 | folderPath := pathpre.VscodeURIToString(oneFolder.URI) 23 | l.removeWorkspaceFolder(ctx, folderPath) 24 | } 25 | return nil 26 | } 27 | 28 | // addWorkspaceFolder 处理增加文件夹 29 | func (l *LspServer)addWorkspaceFolder(ctx context.Context, dirpath string) { 30 | l.requestMutex.Lock() 31 | defer l.requestMutex.Unlock() 32 | dirManager := common.GConfig.GetDirManager() 33 | 34 | // 若增加的是当前workspace 文件夹中包含的子文件夹, 则不需要做任何处理 35 | if dirManager.IsDirExistWorkspace(dirpath) { 36 | log.Debug("current added dir=%s has existed in the workspaceFolder, not need analysis", dirpath) 37 | return 38 | } 39 | dirManager.PushOneSubDir(dirpath) 40 | 41 | allProject := l.getAllProject() 42 | 43 | // 获取当前文件夹下所有lua文件 44 | addFiles := dirManager.GetDirFileList(dirpath, false) 45 | 46 | // 设置所有增加文件的事件 47 | addFileEvent := make([]check.FileEventStruct, 0, len(addFiles)) 48 | for _, file := range addFiles { 49 | addFileEvent = append(addFileEvent, check.FileEventStruct{ 50 | StrFile: file, 51 | Type: 1, 52 | }) 53 | // 文件有变更了,清除临时的错误显示 54 | l.ClearChangeFileErr(ctx, file) 55 | } 56 | 57 | if len(addFileEvent) > 0 { 58 | // 需要去处理文件的变化 59 | log.Debug("need to handle file venent changes num=%d", len(addFileEvent)) 60 | // 处理所有的文件变化 61 | allProject.HandleFileEventChanges(addFileEvent) 62 | 63 | // 再一次获取所有诊断信息 64 | l.pushAllDiagnosticsAgain(ctx) 65 | } 66 | 67 | // 更新下需要统计的信息 68 | l.SetLuaFileNumber(allProject.GetAllFileNumber()) 69 | } 70 | 71 | // removeWorkspaceFolder 处理移除文件夹 72 | func (l *LspServer)removeWorkspaceFolder(ctx context.Context, dirpath string) { 73 | l.requestMutex.Lock() 74 | defer l.requestMutex.Unlock() 75 | dirManager := common.GConfig.GetDirManager() 76 | 77 | if !dirManager.RemoveOneSubDir(dirpath) { 78 | log.Debug("remove error :%s", dirpath) 79 | } 80 | 81 | // 若移除的是subDirs 中的文件夹, 则直接进行所有文件删除处理 82 | allProject := l.getAllProject() 83 | allFilesMap := allProject.GetAllFilesMap() 84 | 85 | // 获取当前文件夹下所有lua文件 86 | removedFiles := dirManager.GetDirFileList(dirpath, false) 87 | 88 | delFileEvent := make([]check.FileEventStruct, 0, len(removedFiles)) 89 | for _, file := range removedFiles { 90 | if _, ok := allFilesMap[file]; !ok { 91 | continue 92 | } 93 | delFileEvent = append(delFileEvent, check.FileEventStruct{ 94 | StrFile: file, 95 | Type: 3, 96 | }) 97 | // 文件有变更了,清除临时的错误显示 98 | l.ClearChangeFileErr(ctx, file) 99 | l.ClearOneFileDiagnostic(ctx, file) 100 | l.RemoveFile(file) 101 | } 102 | 103 | if len(delFileEvent) > 0 { 104 | // 需要去处理文件的变化 105 | log.Debug("need to handle file venent changes num=%d", len(delFileEvent)) 106 | // 处理所有的文件变化 107 | allProject.HandleFileEventChanges(delFileEvent) 108 | 109 | // 再一次获取所有诊断信息 110 | l.pushAllDiagnosticsAgain(ctx) 111 | } 112 | 113 | // 更新下需要统计的信息 114 | l.SetLuaFileNumber(allProject.GetAllFileNumber()) 115 | } 116 | -------------------------------------------------------------------------------- /luahelper-lsp/langserver/workspace_symbol.go: -------------------------------------------------------------------------------- 1 | package langserver 2 | 3 | import ( 4 | "context" 5 | "luahelper-lsp/langserver/check/common" 6 | "luahelper-lsp/langserver/lspcommon" 7 | lsp "luahelper-lsp/langserver/protocol" 8 | ) 9 | 10 | // WorkspaceSymbolRequest 全工程符合查找提示,返回多个符合 11 | func (l *LspServer) WorkspaceSymbolRequest(ctx context.Context, vs lsp.WorkspaceSymbolParams) (items []lsp.SymbolInformation, err error) { 12 | project := l.getAllProject() 13 | fileSymbolVec := project.FindWorkspaceAllSymbol(vs.Query) 14 | 15 | vecLen := len(fileSymbolVec) 16 | items = make([]lsp.SymbolInformation, 0, vecLen) 17 | 18 | for _, oneSymbol := range fileSymbolVec { 19 | loc := lsp.Location{ 20 | URI: lspcommon.GetFileDocumentURI(oneSymbol.FileName), 21 | Range: lspcommon.LocToRange(&oneSymbol.Loc), 22 | } 23 | 24 | item := lsp.SymbolInformation{ 25 | Name: oneSymbol.Name, 26 | Kind: lsp.Variable, 27 | Location: loc, 28 | ContainerName: oneSymbol.ContainerName, 29 | } 30 | 31 | if oneSymbol.Kind == common.IKFunction { 32 | item.Kind = lsp.Function 33 | } else if oneSymbol.Kind == common.IKAnnotateClass { 34 | item.Kind = lsp.Interface 35 | } else if oneSymbol.Kind == common.IKAnnotateAlias { 36 | item.Kind = lsp.Interface 37 | } 38 | items = append(items, item) 39 | } 40 | 41 | return 42 | } 43 | -------------------------------------------------------------------------------- /luahelper-lsp/mac.sh: -------------------------------------------------------------------------------- 1 | mv luahelper-lsp ./../luahelper-vscode/server/maclualsp 2 | -------------------------------------------------------------------------------- /luahelper-lsp/mac_arm64_mv.sh: -------------------------------------------------------------------------------- 1 | mv luahelper-lsp ./../luahelper-vscode/server/armmaclualsp 2 | -------------------------------------------------------------------------------- /luahelper-lsp/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "io" 6 | "net" 7 | "net/http" 8 | _ "net/http/pprof" 9 | "os" 10 | "sync" 11 | 12 | "luahelper-lsp/langserver" 13 | "luahelper-lsp/langserver/check/common" 14 | "luahelper-lsp/langserver/log" 15 | 16 | "github.com/yinfei8/jrpc2/channel" 17 | ) 18 | 19 | func main() { 20 | modeFlag := flag.Int("mode", 0, "mode type, 0 is run cmd, 1 is local rpc, 2 is socket rpc") 21 | logFlag := flag.Int("logflag", 0, "0 is not open log, 1 is open log") 22 | localpath := flag.String("localpath", "", "local project path") 23 | flag.Parse() 24 | 25 | // 是否开启日志 26 | enableLog := false 27 | if *logFlag == 1 { 28 | enableLog = true 29 | } 30 | 31 | // socket rpc时,默认开启日志,方便定位问题 32 | if *modeFlag == 2 { 33 | enableLog = true 34 | } 35 | 36 | // 开启日志时,才开启pprof 37 | if enableLog { 38 | go func() { 39 | http.ListenAndServe("localhost:6060", nil) 40 | }() 41 | } 42 | 43 | // 初始化为日志系统 44 | log.InitLog(enableLog) 45 | 46 | common.GlobalConfigDefautInit() 47 | common.GConfig.IntialGlobalVar() 48 | 49 | //*modeFlag = 0 50 | if *modeFlag == 1 { 51 | cmdRPC() 52 | } else if *modeFlag == 2 { 53 | socketRPC() 54 | } else if *modeFlag == 0 { 55 | runLocalDiagnostices(*localpath) 56 | } 57 | } 58 | 59 | // cmd 的方式运行rpc 60 | func cmdRPC() { 61 | log.Debug("local stat running ....") 62 | Server := langserver.CreateServer() 63 | Server.Start(channel.Header("")(os.Stdin, os.Stdout)) 64 | 65 | log.Debug("Server started ....") 66 | if err := Server.Wait(); err != nil { 67 | log.Debug("Server exited: %v", err) 68 | } 69 | log.Debug("Server exited return") 70 | } 71 | 72 | // 网络的方式运行rpc 73 | func socketRPC() { 74 | log.Debug("socket running ....") 75 | lst, err := net.Listen("tcp", "localhost:7778") 76 | if err != nil { 77 | log.Error("Listen: %v", err) 78 | return 79 | } 80 | 81 | var wg sync.WaitGroup 82 | for { 83 | conn, err := lst.Accept() 84 | log.Debug("accept new conn ....") 85 | Server := langserver.CreateServer() 86 | if err != nil { 87 | if channel.IsErrClosing(err) { 88 | err = nil 89 | } else { 90 | log.Error("Error accepting new connection: %v", err) 91 | } 92 | wg.Wait() 93 | log.Error("Error accepting new connection: %v", err) 94 | return 95 | } 96 | ch := channel.Header("")(conn, conn) 97 | wg.Add(1) 98 | go func() { 99 | defer wg.Done() 100 | Server.Start(ch) 101 | if err := Server.Wait(); err != nil && err != io.EOF { 102 | log.Debug("Server exited: %v", err) 103 | } 104 | 105 | log.Debug("Server exited11: %v", err) 106 | }() 107 | } 108 | } 109 | 110 | func runLocalDiagnostices(localpath string) { 111 | log.Debug("local Diagnostices running ....") 112 | lspServer := langserver.CreateLspServer() 113 | lspServer.RunLocalDiagnostices(localpath) 114 | log.Debug("local Diagnostices exited ") 115 | } 116 | -------------------------------------------------------------------------------- /luahelper-lsp/mv.sh: -------------------------------------------------------------------------------- 1 | mv luahelper-lsp ./../luahelper-vscode/server/linuxlualsp 2 | -------------------------------------------------------------------------------- /luahelper-lsp/testdata/complete/intelligent3/test_intelligent3.lua: -------------------------------------------------------------------------------- 1 | --abcdd = {} 2 | print(abcdd.a) 3 | abcdd.addd().ddd.dddp() 4 | abcdd.eff() 5 | abcdd.addd().ddd.dddp() 6 | abcdd.eff() 7 | abcdd:dd().dd1() 8 | abcdd:dd().dd1() 9 | 10 | print(abcdd.addd().ddd.a.d) 11 | print(abcdd.addd().ddd.dd.ddd) 12 | 13 | abcdd:dd() 14 | abcdd.ccc(one, one).a.b.c() 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /luahelper-lsp/testdata/complete/test1.lua: -------------------------------------------------------------------------------- 1 | local abc = 1; -------------------------------------------------------------------------------- /luahelper-lsp/testdata/complete/test10.lua: -------------------------------------------------------------------------------- 1 | ---@type table 2 | local dd = { 3 | a = 1, 4 | b = 2, 5 | c = 3 6 | } 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /luahelper-lsp/testdata/complete/test2.lua: -------------------------------------------------------------------------------- 1 | ---@class uiButton 2 | local uiButton = class('uiButton') 3 | 4 | ---@return uiButton 5 | function uiButton:new() 6 | return self 7 | end 8 | 9 | ---@return uiButton 10 | function uiButton:setX(x) 11 | self.x_ = x 12 | return self 13 | end 14 | 15 | ---@return uiButton 16 | function uiButton:setY(y) 17 | self.y_ = y 18 | self.setY():setY():setY():setY() 19 | return self 20 | end 21 | 22 | local btn1 = uiButton.new() -- 返回类型 uiButton 23 | 24 | local btn2 = uiButton.new():setX(10) -- 返回类型 any 25 | 26 | local btn3 = uiButton.new():setX(10):setY(10) -- 返回类型 any 27 | 28 | _G.aaa = uiButton.new() 29 | local btn4 = _G.aaa.setX().setX():setX():setX():setX() 30 | 31 | local btn5 = uiButton:setX(1) 32 | 33 | ---@return uiButton 34 | function setYa(y) 35 | self.y_ = y 36 | uiButton.setY():setY():setY():setY().setX() 37 | return self 38 | end 39 | 40 | local btn6 = setYa(); 41 | local btn7 = setYa().setX(); 42 | 43 | 44 | ---@return uiButton 45 | function uiButton:setY1(y) 46 | local btn8 = self:setX() 47 | local btn9 = self:setY() 48 | 49 | end 50 | 51 | -------------------------------------------------------------------------------- /luahelper-lsp/testdata/complete/test3.lua: -------------------------------------------------------------------------------- 1 | local a = require("test3_require") 2 | local b = require("test3_require2").d 3 | 4 | local c = { 5 | a = 1, 6 | b = 2, 7 | c = { 8 | d = { 9 | f = 1 10 | } 11 | } 12 | } 13 | 14 | local d = (require "test3_require") 15 | -------------------------------------------------------------------------------- /luahelper-lsp/testdata/complete/test3_require.lua: -------------------------------------------------------------------------------- 1 | local a = { 2 | b = 1, 3 | c = 2, 4 | f = { 5 | d = 1, 6 | g = 1, 7 | } 8 | } 9 | 10 | a.d = { 11 | a = 1, 12 | b = 2 13 | } 14 | 15 | a.e = 2 16 | 17 | local a1 = a 18 | local a2 = a 19 | 20 | return a2 -------------------------------------------------------------------------------- /luahelper-lsp/testdata/complete/test3_require2.lua: -------------------------------------------------------------------------------- 1 | 2 | return { 3 | b = 1, 4 | c = 2, 5 | e = 3, 6 | d = { 7 | a = 1, 8 | b = 2 9 | }, 10 | f = { 11 | d = 1, 12 | g = 2, 13 | } 14 | } -------------------------------------------------------------------------------- /luahelper-lsp/testdata/complete/test4.lua: -------------------------------------------------------------------------------- 1 | local abcdefg = {} 2 | abcdefg.abc = 1 3 | 4 | 5 | -------------------------------------------------------------------------------- /luahelper-lsp/testdata/complete/test5.lua: -------------------------------------------------------------------------------- 1 | local function func1() 2 | return { 3 | a = 1, 4 | b = { 5 | b1 = { 6 | b2 = 1 7 | } 8 | } 9 | } 10 | end 11 | 12 | local c2 = { 13 | a = 1, 14 | b = { 15 | b1 = { 16 | b2 = 1 17 | } 18 | } 19 | } 20 | 21 | local f1 = func1() 22 | 23 | f1.b. 24 | c2.b.b1.b2 -------------------------------------------------------------------------------- /luahelper-lsp/testdata/complete/test6.lua: -------------------------------------------------------------------------------- 1 | local abcdef = { 2 | anumber = 1, 3 | bstring = "string", 4 | cany = b, 5 | dtable = {} 6 | } 7 | print(abcdef) 8 | 9 | local cdef123 = abcdef 10 | print(cdef123) 11 | 12 | -------------------------------------------------------------------------------- /luahelper-lsp/testdata/complete/test7.lua: -------------------------------------------------------------------------------- 1 | ---@class one11 2 | ---@field astring string 3 | ---@field bnumber number 4 | ---@field cany any 5 | ---@field dfun fun(a:number, b:number) 6 | 7 | ---@type one11 8 | local aaaa1 = {} 9 | aaaa1.abc = 1 10 | 11 | local aaaaa2 = aaaa1 12 | 13 | 14 | -------------------------------------------------------------------------------- /luahelper-lsp/testdata/complete/test8.lua: -------------------------------------------------------------------------------- 1 | ---@class lose_label_data @用户回流标签数据 2 | local lose_label_data = { 3 | open_flag = 1, -- 开启的标记 4 | open_time = now, -- 回流标记初始化的时间,后面在7天内,累计登录的前3日,每次都给自己活跃好友发送信息 5 | continue_day_num = 1, -- 会回流后,7天内累计登录的天数 6 | ---@type number[] @邀请自己组队的列表,最多存储10个 7 | invite_self_list = { 8 | -- [1] = uid1, -- 存储好友的uid1 9 | -- [2] = uid2, -- 存储好友的uid2 10 | }, 11 | get_flag = 0 -- 拉取状态值,整个系统依赖于好友是否在线和好友的亲密度;存储的是 get_interface_array 位数据 12 | } 13 | 14 | ---@type lose_label_data 15 | local lose_label_data = {} 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /luahelper-lsp/testdata/complete/test9.lua: -------------------------------------------------------------------------------- 1 | coroutine.start = function () 2 | 3 | end 4 | 5 | local a = coroutine 6 | -------------------------------------------------------------------------------- /luahelper-lsp/testdata/complete/test_alias1.lua: -------------------------------------------------------------------------------- 1 | print(1) 2 | ---@alias popenmode4 3 | ---| '"r"' # Read data 4 | ---| '"w"' # Write data to this program by `file`. 5 | ---| "fsfsfsf" # acddd 6 | 7 | ---@param prog string @djfosjf 8 | ---@param mode popenmode4 @fjosof 9 | function popen4(prog, mode) 10 | local b = mode 11 | end 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /luahelper-lsp/testdata/complete/test_intelligent1.lua: -------------------------------------------------------------------------------- 1 | abcdd = {} 2 | print(abcdd.a) 3 | abcdd.addd().ddd.dddp() 4 | abcdd.eff() 5 | abcdd.addd().ddd.dddp() 6 | abcdd.eff() 7 | abcdd:dd().dd1() 8 | abcdd:dd().dd1() 9 | 10 | print(abcdd.addd().ddd.a.d) 11 | print(abcdd.addd().ddd.dd.ddd) 12 | 13 | abcdd:dd() 14 | abcdd.ccc(one, one).a.b.c() 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /luahelper-lsp/testdata/complete/test_intelligent2.lua: -------------------------------------------------------------------------------- 1 | local abcdd = {} 2 | print(abcdd.a) 3 | abcdd.addd().ddd.dddp() 4 | abcdd.eff() 5 | abcdd.addd().ddd.dddp() 6 | abcdd.eff() 7 | abcdd:dd().dd1() 8 | abcdd:dd().dd1() 9 | 10 | print(abcdd.addd().ddd.a.d) 11 | print(abcdd.addd().ddd.dd.ddd) 12 | 13 | abcdd:dd() 14 | abcdd.ccc(one, one).a.b.c() 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /luahelper-lsp/testdata/complete/test_table_key.lua: -------------------------------------------------------------------------------- 1 | ---@class one111 2 | ---@field one number @dsfosf 3 | ---@field two number @fdsfos 4 | 5 | function ssfsfsf() 6 | ---@type one111 7 | local a2 = { 8 | o = 1, 9 | 10 | 11 | } 12 | end -------------------------------------------------------------------------------- /luahelper-lsp/testdata/define/be_define.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-lsp/testdata/define/be_define.lua -------------------------------------------------------------------------------- /luahelper-lsp/testdata/define/definefolder/init.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-lsp/testdata/define/definefolder/init.lua -------------------------------------------------------------------------------- /luahelper-lsp/testdata/define/test1.lua: -------------------------------------------------------------------------------- 1 | if d then 2 | 3 | end 4 | 5 | 6 | local var = nil 7 | if var then 8 | print(var) 9 | elseif a then 10 | 11 | end 12 | 13 | 14 | 15 | if a then 16 | print(a) 17 | end 18 | 19 | while condition do 20 | 21 | end 22 | 23 | dfjsofjao 24 | sfjosjaf 25 | if faf fsf 26 | elseif fsf ffa 27 | end 28 | 29 | dd = 1 30 | local ddd = {} 31 | ddd.b = 1 32 | d[#ddd] = 2 33 | d[#dd]=3 34 | d[#ddd.b + #ddd.b] = #dd + 1 35 | d[#ddd.b + 1] = #dd + 1 -------------------------------------------------------------------------------- /luahelper-lsp/testdata/define/test2.lua: -------------------------------------------------------------------------------- 1 | local ppp = require("definefolder") -------------------------------------------------------------------------------- /luahelper-lsp/testdata/define/test3.lua: -------------------------------------------------------------------------------- 1 | local ppp = require("be_define") -------------------------------------------------------------------------------- /luahelper-lsp/testdata/define/test4.lua: -------------------------------------------------------------------------------- 1 | local ppp = import("be_define.lua") -------------------------------------------------------------------------------- /luahelper-lsp/testdata/define/test5.lua: -------------------------------------------------------------------------------- 1 | local foo = {} 2 | 3 | function foo:test() 4 | local foo = {} 5 | self:bar() 6 | end 7 | 8 | function foo:bar() 9 | end -------------------------------------------------------------------------------- /luahelper-lsp/testdata/hover/hover1.lua: -------------------------------------------------------------------------------- 1 | ---@class uiButton 2 | local uiButton = class('uiButton') 3 | 4 | ---@return uiButton 5 | function uiButton.new() 6 | return self 7 | end 8 | 9 | ---@return uiButton 10 | function uiButton:setX(x) 11 | self.x_ = x 12 | return self 13 | end 14 | 15 | ---@return uiButton 16 | function uiButton:setY(y) 17 | self.y_ = y 18 | self.setY():setY():setY():setY() 19 | return self 20 | end 21 | 22 | local btn1 = uiButton.new() -- 返回类型 uiButton 23 | 24 | local btn2 = uiButton.new():setX(10) -- 返回类型 any 25 | 26 | local btn3 = uiButton.new():setX(10):setY(10) -- 返回类型 any 27 | 28 | _G.aaa = uiButton.new() 29 | local btn4 = _G.aaa.setX().setX():setX():setX():setX() 30 | 31 | local btn5 = uiButton:setX(1) 32 | 33 | ---@return uiButton 34 | function setYa(y) 35 | self.y_ = y 36 | uiButton.setY():setY():setY():setY().setX() 37 | return self 38 | end 39 | 40 | local btn6 = setYa(); 41 | local btn7 = setYa().setX(); 42 | 43 | 44 | ---@return uiButton 45 | function uiButton:setY1(y) 46 | local btn8 = self:setX() 47 | local btn9 = self:setY() 48 | end 49 | -------------------------------------------------------------------------------- /luahelper-lsp/testdata/hover/hover10.lua: -------------------------------------------------------------------------------- 1 | local a1 = function(a, b) 2 | return { 3 | a = 1, 4 | b = 2 5 | } 6 | end 7 | 8 | local bbbb = setmetatable({}, {__call = a1}) 9 | local aaaa = bbbb() 10 | 11 | local cccc = setmetatable({}, {__call = function(a, b) 12 | return { 13 | a = 1, 14 | b = 2 15 | } 16 | end}) 17 | 18 | local dddd = cccc() -------------------------------------------------------------------------------- /luahelper-lsp/testdata/hover/hover11.lua: -------------------------------------------------------------------------------- 1 | local now 2 | 3 | ---@class lose_battle_backflow 4 | ---@field open_flag number 5 | ---@field open_time number 6 | ---@field last_update_time number 7 | ---@field continue_day_num number 8 | local back_flow = { 9 | open_flag = 1, 10 | open_time = now, 11 | last_update_time = now, 12 | continue_day_num = 1 13 | } 14 | 15 | print(back_flow) -------------------------------------------------------------------------------- /luahelper-lsp/testdata/hover/hover2.lua: -------------------------------------------------------------------------------- 1 | local req_v = require("hover2_requrie") 2 | 3 | print(req_v.b) 4 | print(req_v.e) 5 | print(req_v.f) 6 | print(req_v.f.d) 7 | print(req_v.d) 8 | print(req_v.d.b) 9 | 10 | local req_f = require("hover2_requrie").f 11 | print(req_f.d) 12 | 13 | local req_d = require("hover2_requrie").d 14 | print(req_d.a) 15 | 16 | 17 | -- hover2_requrie2 18 | local req_v = require("hover2_requrie2") 19 | 20 | print(req_v.b) 21 | print(req_v.f) 22 | print(req_v.f.d) 23 | print(req_v.d) 24 | 25 | local req_f = require("hover2_requrie").f 26 | print(req_f.d) 27 | 28 | print(require("hover2_requrie").d.a) -------------------------------------------------------------------------------- /luahelper-lsp/testdata/hover/hover2_requrie.lua: -------------------------------------------------------------------------------- 1 | local a = { 2 | b = 1, 3 | c = 2, 4 | f = { 5 | d = 1, 6 | g = 1, 7 | } 8 | } 9 | 10 | a.d = { 11 | a = 1, 12 | b = 2 13 | } 14 | 15 | a.e = 2 16 | 17 | local a1 = a 18 | local a2 = a 19 | 20 | return a2 -------------------------------------------------------------------------------- /luahelper-lsp/testdata/hover/hover2_requrie2.lua: -------------------------------------------------------------------------------- 1 | 2 | return { 3 | b = 1, 4 | c = 2, 5 | e = 3, 6 | d = { 7 | a = 1, 8 | b = 2 9 | }, 10 | f = { 11 | d = 1, 12 | g = 2, 13 | } 14 | } -------------------------------------------------------------------------------- /luahelper-lsp/testdata/hover/hover3.lua: -------------------------------------------------------------------------------- 1 | local a = { 2 | b = 1, 3 | c = 2, 4 | d = { 5 | a = 1, 6 | b = 2 7 | } 8 | } 9 | 10 | a.e = 1 11 | a.f = { 12 | a = 1, 13 | b = 2 14 | } 15 | 16 | local a1 = a 17 | local a2 = a1 18 | local exa_a = a2 19 | print(exa_a.b) 20 | print(exa_a.e) 21 | print(exa_a.f) 22 | print(exa_a.f.b) 23 | print(exa_a.d) -------------------------------------------------------------------------------- /luahelper-lsp/testdata/hover/hover4.lua: -------------------------------------------------------------------------------- 1 | local imp_4 = import("hover4_import.lua") 2 | 3 | print(imp_4.aaa) 4 | print(imp_4.ddd) 5 | print(imp_4.bbb) 6 | print(imp_4.ccc) -------------------------------------------------------------------------------- /luahelper-lsp/testdata/hover/hover4_import.lua: -------------------------------------------------------------------------------- 1 | local aaa = 1 2 | ddd = 2 3 | 4 | function bbb() 5 | print("bb") 6 | end 7 | 8 | local function ccc() 9 | print("ccc") 10 | end -------------------------------------------------------------------------------- /luahelper-lsp/testdata/hover/hover5.lua: -------------------------------------------------------------------------------- 1 | local abcd = { 2 | anumber = 1, 3 | bstring = "string", 4 | cany = b, 5 | dtable = {} 6 | } 7 | print(abcd) 8 | 9 | local cdef = abcd 10 | print(cdef) -------------------------------------------------------------------------------- /luahelper-lsp/testdata/hover/hover6.lua: -------------------------------------------------------------------------------- 1 | ---@class one11 2 | ---@field astring string 3 | ---@field bnumber number 4 | ---@field cany any 5 | ---@field dfun fun(a:number, b:number) 6 | 7 | ---@type one11 8 | local aaaa1 = {} 9 | aaaa1.abc = 1 10 | 11 | local aaaaa2 = aaaa1 12 | 13 | aaaa1.bnumber = 2 14 | aaaa1.astring = "sfs" 15 | aaaaa2.bnumber = 2 16 | aaaaa2.astring = "sfs" -------------------------------------------------------------------------------- /luahelper-lsp/testdata/hover/hover7.lua: -------------------------------------------------------------------------------- 1 | ---@class lose_label_data @用户回流标签数据 2 | local lose_label_data = { 3 | open_flag = 1, -- 开启的标记 4 | open_time = now, -- 回流标记初始化的时间,后面在7天内,累计登录的前3日,每次都给自己活跃好友发送信息 5 | continue_day_num = 1, -- 会回流后,7天内累计登录的天数 6 | ---@type number[] @邀请自己组队的列表,最多存储10个 7 | invite_self_list = { 8 | -- [1] = uid1, -- 存储好友的uid1 9 | -- [2] = uid2, -- 存储好友的uid2 10 | }, 11 | get_flag = 0 -- 拉取状态值,整个系统依赖于好友是否在线和好友的亲密度;存储的是 get_interface_array 位数据 12 | } 13 | 14 | ---@type lose_label_data 15 | local lose_label_data = {} -------------------------------------------------------------------------------- /luahelper-lsp/testdata/hover/hover8.lua: -------------------------------------------------------------------------------- 1 | test2 = function() 2 | ---@class test1 3 | ---@field aa number @AAA 4 | ---@field cc number @BBB 5 | ---@type test1 6 | local default = { 7 | aa = 1, 8 | bb = 2, 9 | } 10 | 11 | return default 12 | end 13 | 14 | local yy = test2() -------------------------------------------------------------------------------- /luahelper-lsp/testdata/hover/hover9.lua: -------------------------------------------------------------------------------- 1 | local a = { 2 | aaa = 1, 3 | bbb = 2 4 | } 5 | 6 | local bbbb = setmetatable({}, {__index = a}) 7 | 8 | local b = { 9 | ccc = 1, 10 | ddd = 2 11 | } 12 | 13 | local eeee = setmetatable(b, {}) 14 | local ffff = setmetatable(b, {__index = a}) -------------------------------------------------------------------------------- /luahelper-lsp/testdata/hover/hover_expand_g.lua: -------------------------------------------------------------------------------- 1 | _G.abcdd = {} 2 | abcdd.a = 1 3 | print(abcdd.a) 4 | print(abcdd.a) 5 | print(abcdd.bbb.q.b) 6 | print(abcdd.bbb.qqqqqq.d.d) 7 | print(abcdd.bbb.q) -------------------------------------------------------------------------------- /luahelper-lsp/testdata/hover/hover_expand_local.lua: -------------------------------------------------------------------------------- 1 | local abcdd = {} 2 | abcdd.a = 1 3 | print(abcdd.a) 4 | print(abcdd.a) 5 | print(abcdd.bbb.q.b) 6 | print(abcdd.bbb.qqqqqq.d.d) 7 | print(abcdd.bbb.q) -------------------------------------------------------------------------------- /luahelper-lsp/testdata/hover/hover_expand_no.lua: -------------------------------------------------------------------------------- 1 | --local abcdd = {} 2 | abcdd.a = 1 3 | print(abcdd.a) 4 | print(abcdd.a) 5 | print(abcdd.bbb.q.b) 6 | print(abcdd.bbb.qqqqqq.d.d) 7 | print(abcdd.bbb.q) -------------------------------------------------------------------------------- /luahelper-lsp/testdata/hover/hover_func_return.lua: -------------------------------------------------------------------------------- 1 | function func2() 2 | return "a", "b", "c" 3 | end 4 | 5 | ---@param one string @djofo 6 | local function func1(one, two, c) 7 | if two == 1 then 8 | return func1() 9 | end 10 | 11 | print(two.b.c) 12 | 13 | return func2(), func2(), func1 14 | end -------------------------------------------------------------------------------- /luahelper-lsp/testdata/parse/test1.lua: -------------------------------------------------------------------------------- 1 | local one = 1 2 | math.abs(1) 3 | 4 | ---@type ... 5 | local one 6 | a.c.b.d 7 | 尹飞 8 | 9 | 尹飞 10 | 11 | fsfsd 12 | 13 | adfs.b 14 | bbs 15 | sfj 16 | afdsf 17 | ff 18 | fsf.bbbS 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | local ppd = 1 27 | local pp=1 28 | print(ppd) 29 | local a ,b = 1 30 | print(ppd) 31 | print(ppd) 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /luahelper-lsp/testdata/parse/test2.lua: -------------------------------------------------------------------------------- 1 | local abcdef = { 2 | anumber = 1, 3 | bstring = "string", 4 | cany = b, 5 | dtable = { 6 | a = 7 | } 8 | } 9 | print(abcdef) 10 | 11 | local cdef123 = abcdef 12 | print(cdef123) 13 | 14 | afjsofjao -------------------------------------------------------------------------------- /luahelper-lsp/testdata/project/globalVar/one.lua: -------------------------------------------------------------------------------- 1 | abcd = { 2 | aaa = 1, 3 | bbb = 2 4 | } -------------------------------------------------------------------------------- /luahelper-lsp/testdata/project/globalVar/three.lua: -------------------------------------------------------------------------------- 1 | print(abcd.ccc) 2 | print(abcd.eee) 3 | 4 | -------------------------------------------------------------------------------- /luahelper-lsp/testdata/project/globalVar/two.lua: -------------------------------------------------------------------------------- 1 | abcd.ccc = 1 2 | abcd.ddd = 2 3 | -------------------------------------------------------------------------------- /luahelper-lsp/testdata/project/globalVar/two1.lua: -------------------------------------------------------------------------------- 1 | _G.abcd.eee = 1 -------------------------------------------------------------------------------- /luahelper-lsp/testdata/project/test1/test1.lua: -------------------------------------------------------------------------------- 1 | ---@enum start @comment 表示枚举段的开始 2 | item_type_chest_cash = 49; --现金或者Q币 3 | item_type_facial_expression = 49; -- 面部表情 4 | item_type_home_ticket = 87; --家园商城供货券 5 | local a = 1 6 | local b = 2 7 | local c = 1 8 | ---@enum end @comment 表示枚举段的结束 9 | 10 | ---@type enum table 11 | item_type = { 12 | chest_cash = 1, 13 | facial_expression = 1, 14 | home_ticket = 2 15 | } 16 | 17 | ---@type enum table 18 | local item_type1 = { 19 | chest_cash = 1, 20 | facial_expression = 1, 21 | home_ticket = 2 22 | } 23 | -------------------------------------------------------------------------------- /luahelper-vscode/.gitignore: -------------------------------------------------------------------------------- 1 | out 2 | node_modules 3 | .vscode-test 4 | *.vsix 5 | 6 | *.iml 7 | .gradle 8 | .idea 9 | temp 10 | /debugger 11 | /server 12 | /package-lock.json 13 | /temp -------------------------------------------------------------------------------- /luahelper-vscode/.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | os: osx 3 | node_js: 4 | - node 5 | script: 6 | - npm i vsce -g 7 | - node ./build/prepare-version.js 8 | - node ./build/prepare.js 9 | - vsce package -------------------------------------------------------------------------------- /luahelper-vscode/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "eg2.tslint" 6 | ] 7 | } -------------------------------------------------------------------------------- /luahelper-vscode/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // A launch configuration that compiles the extension and then opens it inside a new window 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | { 6 | "version": "0.2.0", 7 | "configurations": [ 8 | { 9 | "name": "Extension", 10 | "type": "extensionHost", 11 | "request": "launch", 12 | "runtimeExecutable": "${execPath}", 13 | "args": [ 14 | "--extensionDevelopmentPath=${workspaceFolder}" 15 | ], 16 | "outFiles": [ 17 | "${workspaceFolder}/out/**/*.js" 18 | ], 19 | "env": { 20 | "DEBUG_MODE": "true" 21 | }, 22 | "preLaunchTask": "npm: watch" 23 | }, 24 | { 25 | "name": "Extension Tests", 26 | "type": "extensionHost", 27 | "request": "launch", 28 | "runtimeExecutable": "${execPath}", 29 | "args": [ 30 | "--extensionDevelopmentPath=${workspaceFolder}", 31 | "--extensionTestsPath=${workspaceFolder}/out/test" 32 | ], 33 | "outFiles": [ 34 | "${workspaceFolder}/out/test/**/*.js" 35 | ], 36 | "preLaunchTask": "npm: watch" 37 | } 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /luahelper-vscode/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "files.exclude": { 4 | "out": false // set this to true to hide the "out" folder with the compiled JS files 5 | }, 6 | "search.exclude": { 7 | "out": true // set this to false to include "out" folder in search results 8 | }, 9 | "editor.snippetSuggestions": "bottom", 10 | } -------------------------------------------------------------------------------- /luahelper-vscode/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | // See https://go.microsoft.com/fwlink/?LinkId=733558 2 | // for the documentation about the tasks.json format 3 | { 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "type": "npm", 8 | "script": "watch", 9 | "problemMatcher": "$tsc-watch", 10 | "isBackground": true, 11 | "presentation": { 12 | "reveal": "never" 13 | }, 14 | "group": { 15 | "kind": "build", 16 | "isDefault": true 17 | } 18 | } 19 | ] 20 | } -------------------------------------------------------------------------------- /luahelper-vscode/.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | out/test/** 4 | out/**/*.map 5 | src/** 6 | build/** 7 | temp 8 | .gitignore 9 | tsconfig.json 10 | vsc-extension-quickstart.md 11 | tslint.json 12 | build.sh 13 | prepare-version.js -------------------------------------------------------------------------------- /luahelper-vscode/appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 0.3.{build} 2 | image: Ubuntu1804 3 | stack: node 12 4 | build_script: 5 | - sh: >- 6 | npm i 7 | 8 | npm i vsce -g 9 | 10 | node ./build/prepare-version.js 11 | 12 | node ./build/prepare.js 13 | 14 | vsce package 15 | artifacts: 16 | - path: '*.vsix' -------------------------------------------------------------------------------- /luahelper-vscode/build/config.js: -------------------------------------------------------------------------------- 1 | exports.default = { 2 | emmyDebuggerVersion: '1.0.12', 3 | emmyDebuggerUrl: 'https://github.com/EmmyLua/EmmyLuaDebugger/releases/download', 4 | lanServerVersion: "0.3.4", 5 | lanServerUrl: 'https://github.com/EmmyLua/EmmyLua-LanguageServer/releases/download' 6 | } 7 | -------------------------------------------------------------------------------- /luahelper-vscode/build/prepare-version.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs") 2 | 3 | if (process.env['CI']) { 4 | var version; 5 | if (process.env['TRAVIS']) { 6 | const tag = process.env['TRAVIS_TAG'] 7 | version = tag 8 | } 9 | else if (process.env['APPVEYOR']) { 10 | const tag = process.env['APPVEYOR_REPO_TAG_NAME'] 11 | version = tag || process.env['APPVEYOR_BUILD_VERSION'] 12 | } 13 | 14 | if (version) { 15 | var text = fs.readFileSync('package.json').toString(); 16 | const reg = /\"version\":\s*\"(.+?)\",/; 17 | text = text.replace(reg, `"version": "${version}",`); 18 | fs.writeFileSync('package.json', text); 19 | 20 | console.log(`set version to: ${version}`) 21 | } 22 | } -------------------------------------------------------------------------------- /luahelper-vscode/build/prepare.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const download = require('download'); 3 | const decompress = require('decompress') 4 | const fc = require('filecopy'); 5 | const config = require('./config').default; 6 | 7 | async function downloadTo(url, path) { 8 | return new Promise((r, e) => { 9 | const d = download(url); 10 | d.then(r).catch(err => e(err)); 11 | d.pipe(fs.createWriteStream(path)); 12 | }); 13 | } 14 | 15 | async function build() { 16 | if (!fs.existsSync('temp')) { 17 | fs.mkdirSync('temp') 18 | } 19 | 20 | /*await downloadDepends(); 21 | 22 | // mac 23 | await fc('temp/emmy_core.dylib', 'debugger/emmy/mac/emmy_core.dylib', { mkdirp: true }); 24 | 25 | // linux 26 | await fc('temp/emmy_core.so', 'debugger/emmy/linux/emmy_core.so', { mkdirp: true }); 27 | 28 | // win 29 | await decompress('temp/emmy_core@x86.zip', 'debugger/emmy/windows/x86/'); 30 | await decompress('temp/emmy_core@x64.zip', 'debugger/emmy/windows/x64/'); 31 | 32 | // ls 33 | await fc('temp/EmmyLua-LS-all.jar', 'server/EmmyLua-LS-all.jar', { mkdirp: true }); 34 | */ 35 | } 36 | 37 | build().catch(console.error); -------------------------------------------------------------------------------- /luahelper-vscode/client/3rd/vscode-lua-doc/doc/en-us/54/index.css: -------------------------------------------------------------------------------- 1 | ul { 2 | list-style-type: none ; 3 | } 4 | 5 | ul.contents { 6 | padding: 0 ; 7 | } 8 | 9 | table { 10 | border: none ; 11 | border-spacing: 0 ; 12 | border-collapse: collapse ; 13 | } 14 | 15 | td { 16 | vertical-align: top ; 17 | padding: 0 ; 18 | text-align: left ; 19 | line-height: 1.25 ; 20 | width: 15% ; 21 | } 22 | -------------------------------------------------------------------------------- /luahelper-vscode/client/3rd/vscode-lua-doc/doc/en-us/54/logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/client/3rd/vscode-lua-doc/doc/en-us/54/logo.gif -------------------------------------------------------------------------------- /luahelper-vscode/client/3rd/vscode-lua-doc/doc/en-us/54/lua.css: -------------------------------------------------------------------------------- 1 | html { 2 | background-color: #F8F8F8 ; 3 | } 4 | 5 | body { 6 | background-color: #FFFFFF ; 7 | color: #000000 ; 8 | font-family: Helvetica, Arial, sans-serif ; 9 | text-align: justify ; 10 | line-height: 1.25 ; 11 | margin: 16px auto ; 12 | padding: 32px ; 13 | border: solid #ccc 1px ; 14 | border-radius: 20px ; 15 | max-width: 70em ; 16 | width: 90% ; 17 | } 18 | 19 | h1, h2, h3, h4 { 20 | color: #000080 ; 21 | font-family: Verdana, Geneva, sans-serif ; 22 | font-weight: normal ; 23 | font-style: normal ; 24 | text-align: left ; 25 | } 26 | 27 | h1 { 28 | font-size: 28pt ; 29 | } 30 | 31 | h1 img { 32 | vertical-align: text-bottom ; 33 | } 34 | 35 | h2:before { 36 | content: "\2756" ; 37 | padding-right: 0.5em ; 38 | } 39 | 40 | a { 41 | text-decoration: none ; 42 | } 43 | 44 | a:link { 45 | color: #000080 ; 46 | } 47 | 48 | a:link:hover, a:visited:hover { 49 | background-color: #D0D0FF ; 50 | color: #000080 ; 51 | border-radius: 4px ; 52 | } 53 | 54 | a:link:active, a:visited:active { 55 | color: #FF0000 ; 56 | } 57 | 58 | div.menubar { 59 | padding-bottom: 0.5em ; 60 | } 61 | 62 | p.menubar { 63 | margin-left: 2.5em ; 64 | } 65 | 66 | .menubar a:hover { 67 | margin: -3px -3px -3px -3px ; 68 | padding: 3px 3px 3px 3px ; 69 | border-radius: 4px ; 70 | } 71 | 72 | :target { 73 | background-color: #F0F0F0 ; 74 | margin: -8px ; 75 | padding: 8px ; 76 | border-radius: 8px ; 77 | outline: none ; 78 | } 79 | 80 | hr { 81 | display: none ; 82 | } 83 | 84 | table hr { 85 | background-color: #a0a0a0 ; 86 | color: #a0a0a0 ; 87 | border: 0 ; 88 | height: 1px ; 89 | display: block ; 90 | } 91 | 92 | .footer { 93 | color: gray ; 94 | font-size: x-small ; 95 | text-transform: lowercase ; 96 | } 97 | 98 | input[type=text] { 99 | border: solid #a0a0a0 2px ; 100 | border-radius: 2em ; 101 | background-image: url('images/search.png') ; 102 | background-repeat: no-repeat ; 103 | background-position: 4px center ; 104 | padding-left: 20px ; 105 | height: 2em ; 106 | } 107 | 108 | pre.session { 109 | background-color: #F8F8F8 ; 110 | padding: 1em ; 111 | border-radius: 8px ; 112 | } 113 | 114 | table { 115 | border: none ; 116 | border-spacing: 0 ; 117 | border-collapse: collapse ; 118 | } 119 | 120 | td { 121 | padding: 0 ; 122 | margin: 0 ; 123 | } 124 | 125 | td.gutter { 126 | width: 4% ; 127 | } 128 | 129 | table.columns td { 130 | vertical-align: top ; 131 | padding-bottom: 1em ; 132 | text-align: justify ; 133 | line-height: 1.25 ; 134 | } 135 | 136 | table.book td { 137 | vertical-align: top ; 138 | } 139 | 140 | table.book td.cover { 141 | padding-right: 1em ; 142 | } 143 | 144 | table.book img { 145 | border: solid #000080 1px ; 146 | } 147 | 148 | table.book span { 149 | font-size: small ; 150 | text-align: left ; 151 | display: block ; 152 | margin-top: 0.25em ; 153 | } 154 | 155 | p.logos a:link:hover, p.logos a:visited:hover { 156 | background-color: inherit ; 157 | } 158 | 159 | img { 160 | background-color: white ; 161 | } 162 | -------------------------------------------------------------------------------- /luahelper-vscode/client/3rd/vscode-lua-doc/doc/en-us/54/manual.css: -------------------------------------------------------------------------------- 1 | h3 code { 2 | font-family: inherit ; 3 | font-size: inherit ; 4 | } 5 | 6 | pre, code { 7 | font-size: 12pt ; 8 | } 9 | 10 | span.apii { 11 | color: gray ; 12 | float: right ; 13 | font-family: inherit ; 14 | font-style: normal ; 15 | font-size: small ; 16 | } 17 | 18 | h2:before { 19 | content: "" ; 20 | padding-right: 0em ; 21 | } 22 | -------------------------------------------------------------------------------- /luahelper-vscode/client/3rd/vscode-lua-doc/doc/en-us/54/osi-certified-72x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/client/3rd/vscode-lua-doc/doc/en-us/54/osi-certified-72x60.png -------------------------------------------------------------------------------- /luahelper-vscode/debugger/debugger_lib/plugins/mac/x86_64/501/libpdebug.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/debugger_lib/plugins/mac/x86_64/501/libpdebug.so -------------------------------------------------------------------------------- /luahelper-vscode/debugger/debugger_lib/plugins/mac/x86_64/503/libpdebug.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/debugger_lib/plugins/mac/x86_64/503/libpdebug.so -------------------------------------------------------------------------------- /luahelper-vscode/debugger/debugger_lib/plugins/win/x86/501/libpdebug.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/debugger_lib/plugins/win/x86/501/libpdebug.dll -------------------------------------------------------------------------------- /luahelper-vscode/debugger/debugger_lib/plugins/win/x86/503/libpdebug.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/debugger_lib/plugins/win/x86/503/libpdebug.dll -------------------------------------------------------------------------------- /luahelper-vscode/debugger/debugger_lib/plugins/win/x86_64/501/libpdebug.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/debugger_lib/plugins/win/x86_64/501/libpdebug.dll -------------------------------------------------------------------------------- /luahelper-vscode/debugger/debugger_lib/plugins/win/x86_64/503/libpdebug.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/debugger_lib/plugins/win/x86_64/503/libpdebug.dll -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/linux/lua5.1/lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/linux/lua5.1/lua -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/linux/lua5.1/mime/core.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/linux/lua5.1/mime/core.so -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/linux/lua5.1/socket/core.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/linux/lua5.1/socket/core.so -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/linux/lua5.2/lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/linux/lua5.2/lua -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/linux/lua5.2/mime/core.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/linux/lua5.2/mime/core.so -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/linux/lua5.2/socket/core.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/linux/lua5.2/socket/core.so -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/linux/lua5.3/lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/linux/lua5.3/lua -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/linux/lua5.3/mime/core.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/linux/lua5.3/mime/core.so -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/linux/lua5.3/socket/core.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/linux/lua5.3/socket/core.so -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/linux/lua5.4/lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/linux/lua5.4/lua -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/linux/lua5.4/mime/core.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/linux/lua5.4/mime/core.so -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/linux/lua5.4/socket/core.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/linux/lua5.4/socket/core.so -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/mac/lua5.1/lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/mac/lua5.1/lua -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/mac/lua5.1/mime/core.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/mac/lua5.1/mime/core.so -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/mac/lua5.1/socket/core.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/mac/lua5.1/socket/core.so -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/mac/lua5.2/lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/mac/lua5.2/lua -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/mac/lua5.2/mime/core.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/mac/lua5.2/mime/core.so -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/mac/lua5.2/socket/core.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/mac/lua5.2/socket/core.so -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/mac/lua5.3/lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/mac/lua5.3/lua -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/mac/lua5.3/mime/core.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/mac/lua5.3/mime/core.so -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/mac/lua5.3/socket/core.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/mac/lua5.3/socket/core.so -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/mac/lua5.4/lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/mac/lua5.4/lua -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/mac/lua5.4/mime/core.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/mac/lua5.4/mime/core.so -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/mac/lua5.4/socket/core.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/mac/lua5.4/socket/core.so -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/readme.md: -------------------------------------------------------------------------------- 1 | 本目录下的luasocket二进制文件使用 https://github.com/diegonehab/luasocket 源码编译,区分win和mac平台。 2 | 3 | 1. 部署时把socket和mime两个文件夹拷贝到用户指定的文件夹下,如 `c:/luasocket`。如果这个文件夹中的库不能被lua自动引用,要修改package.cpath,比如 `package.cpath = package.cpath .. ";c:/luasocket/?.dll"`. 4 | 5 | 2. 最后在lua中用 `require("socket.core");` 验证,如无module 'socket.core' not found: 报错,则部署成功。 6 | 7 | 注意调试最好部署在开发环境,不要发布到正式环境。 8 | 9 | -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x64/lua5.1/lua5.1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x64/lua5.1/lua5.1.dll -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x64/lua5.1/lua51.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x64/lua5.1/lua51.exe -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x64/lua5.1/mime/core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x64/lua5.1/mime/core.dll -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x64/lua5.1/socket/core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x64/lua5.1/socket/core.dll -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x64/lua5.2/lua52.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x64/lua5.2/lua52.dll -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x64/lua5.2/lua52.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x64/lua5.2/lua52.exe -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x64/lua5.2/mime/core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x64/lua5.2/mime/core.dll -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x64/lua5.2/socket/core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x64/lua5.2/socket/core.dll -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x64/lua5.3/lua53.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x64/lua5.3/lua53.dll -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x64/lua5.3/lua53.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x64/lua5.3/lua53.exe -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x64/lua5.3/mime/core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x64/lua5.3/mime/core.dll -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x64/lua5.3/socket/core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x64/lua5.3/socket/core.dll -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x64/lua5.4/lua54.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x64/lua5.4/lua54.dll -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x64/lua5.4/lua54.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x64/lua5.4/lua54.exe -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x64/lua5.4/mime/core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x64/lua5.4/mime/core.dll -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x64/lua5.4/socket/core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x64/lua5.4/socket/core.dll -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x86/lua5.1/mime/core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x86/lua5.1/mime/core.dll -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x86/lua5.1/socket/core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x86/lua5.1/socket/core.dll -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x86/lua5.2/mime/core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x86/lua5.2/mime/core.dll -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x86/lua5.2/socket/core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x86/lua5.2/socket/core.dll -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x86/lua5.3/mime/core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x86/lua5.3/mime/core.dll -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x86/lua5.3/socket/core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x86/lua5.3/socket/core.dll -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x86/lua5.4/mime/core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x86/lua5.4/mime/core.dll -------------------------------------------------------------------------------- /luahelper-vscode/debugger/luasocket/win/x86/lua5.4/socket/core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/debugger/luasocket/win/x86/lua5.4/socket/core.dll -------------------------------------------------------------------------------- /luahelper-vscode/images/luahelper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/images/luahelper.png -------------------------------------------------------------------------------- /luahelper-vscode/language-configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "comments": { 3 | "lineComment": "--", 4 | "blockComment": [ "--[[", "]]" ] 5 | }, 6 | "brackets": [ 7 | ["{", "}"], 8 | ["[", "]"], 9 | ["(", ")"] 10 | ], 11 | "autoClosingPairs": [ 12 | ["{", "}"], 13 | ["[", "]"], 14 | ["(", ")"], 15 | ["\"", "\""], 16 | ["'", "'"] 17 | ], 18 | "surroundingPairs": [ 19 | ["{", "}"], 20 | ["[", "]"], 21 | ["(", ")"], 22 | ["\"", "\""], 23 | ["'", "'"] 24 | ], 25 | "folding": { 26 | "markers": { 27 | "start": "^\\s*--@region\\b", 28 | "end": "^\\s*--@endregion\\b" 29 | } 30 | }, 31 | "indentationRules": { 32 | "increaseIndentPattern": "((\\b(else|function|then|do|repeat)\\b((?!\\b(end|until)\\b).)*)|(\\{\\s*))$", 33 | "decreaseIndentPattern": "^\\s*((\\b(elseif|else|end|until)\\b)|(\\})|(\\)))" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /luahelper-vscode/server/armmaclualsp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/server/armmaclualsp -------------------------------------------------------------------------------- /luahelper-vscode/server/darwin/lua-format: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/server/darwin/lua-format -------------------------------------------------------------------------------- /luahelper-vscode/server/linux/lua-format: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/server/linux/lua-format -------------------------------------------------------------------------------- /luahelper-vscode/server/linuxlualsp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/server/linuxlualsp -------------------------------------------------------------------------------- /luahelper-vscode/server/luafmt.config: -------------------------------------------------------------------------------- 1 | column_limit: 120 2 | indent_width: 4 3 | use_tab: false 4 | tab_width: 4 5 | continuation_indent_width: 4 6 | keep_simple_control_block_one_line: false 7 | keep_simple_function_one_line: false 8 | spaces_before_call: 1 9 | align_args: false 10 | break_after_functioncall_lp: false 11 | break_before_functioncall_rp: false 12 | align_parameter: false 13 | chop_down_parameter: false 14 | break_after_functiondef_lp: false 15 | break_before_functiondef_rp: false 16 | align_table_field: true 17 | break_after_table_lb: false 18 | break_before_table_rb: false 19 | chop_down_table: false 20 | chop_down_kv_table: true 21 | table_sep: "," 22 | extra_sep_at_table_end: false 23 | break_after_operator: true 24 | double_quote_to_single_quote: false 25 | single_quote_to_double_quote: false 26 | spaces_inside_functiondef_parens: false 27 | spaces_inside_functioncall_parens: false 28 | spaces_inside_table_braces: false 29 | spaces_around_equals_in_field: true 30 | line_breaks_after_function_body: 1 -------------------------------------------------------------------------------- /luahelper-vscode/server/lualsp.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/server/lualsp.exe -------------------------------------------------------------------------------- /luahelper-vscode/server/maclualsp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/server/maclualsp -------------------------------------------------------------------------------- /luahelper-vscode/server/meta/template/bit.lua: -------------------------------------------------------------------------------- 1 | ---@version JIT 2 | ---@class bitlib 3 | bit = {} 4 | 5 | ---@param x integer 6 | ---@return integer y 7 | function bit.tobit(x) end 8 | 9 | ---@param x integer 10 | ---@param n? integer 11 | ---@return integer y 12 | function bit.tohex(x, n) end 13 | 14 | ---@param x integer 15 | ---@return integer y 16 | function bit.bnot(x) end 17 | 18 | ---@param x integer 19 | ---@param x2 integer 20 | ---@vararg integer 21 | ---@return integer y 22 | function bit.bor(x, x2, ...) end 23 | 24 | ---@param x integer 25 | ---@param x2 integer 26 | ---@vararg integer 27 | ---@return integer y 28 | function bit.band(x, x2, ...) end 29 | 30 | ---@param x integer 31 | ---@param x2 integer 32 | ---@vararg integer 33 | ---@return integer y 34 | function bit.bxor(x, x2, ...) end 35 | 36 | ---@param x integer 37 | ---@param n integer 38 | ---@return integer y 39 | function bit.lshift(x, n) end 40 | 41 | ---@param x integer 42 | ---@param n integer 43 | ---@return integer y 44 | function bit.rshift(x, n) end 45 | 46 | ---@param x integer 47 | ---@param n integer 48 | ---@return integer y 49 | function bit.arshift(x, n) end 50 | 51 | ---@param x integer 52 | ---@param n integer 53 | ---@return integer y 54 | function bit.rol(x, n) end 55 | 56 | ---@param x integer 57 | ---@param n integer 58 | ---@return integer y 59 | function bit.ror(x, n) end 60 | 61 | ---@param x integer 62 | ---@return integer y 63 | function bit.bswap(x) end -------------------------------------------------------------------------------- /luahelper-vscode/server/meta/template/builtin.lua: -------------------------------------------------------------------------------- 1 | ---@class any @any type 2 | 3 | ---@class nil:any @The type `nil` has one single value `nil`, whose main property is to be different from any other value. [`View online doc`](https://www.lua.org/manual/5.4/manual.html#2) | [`View local doc`](command:extension.lua.doc?["en-us/54/manual.html/2"]) 4 | 5 | ---@class boolean: any @The type `boolean` has two values, `false` and `true`. [`View online doc`](https://www.lua.org/manual/5.4/manual.html#2) | [`View local doc`](command:extension.lua.doc?["en-us/54/manual.html/2"]) 6 | 7 | ---@class number:any @The type `number` uses two internal representations, or two subtypes, one called *integer* and the other called *float*. [`View online doc`](https://www.lua.org/manual/5.4/manual.html#2) | [`View local doc`](command:extension.lua.doc?["en-us/54/manual.html/2"]) 8 | 9 | ---@alias integer number @integer numbers 10 | 11 | ---@class thread: any @The type *thread* represents independent threads of execution and it is used to implement coroutines. Lua threads are not related to operating-system threads. Lua supports coroutines on all systems, even thosethat do not support threads natively. [`View online doc`](https://www.lua.org/manual/5.4/manual.html#2) | [`View local doc`](command:extension.lua.doc?["en-us/54/manual.html/2"]) 12 | 13 | ---@class table: any @The type *table* implements associative arrays, that is, arrays that can have as indices not only numbers, but any Lua value except **nil** and NaN.(*Not a Number* is a special floating-point value used by the IEEE 754 standard to represent undefined or unrepresentable numerical results, such as `0/0`.) Tables can be heterogeneous; that is, they can contain values of all types (except **nil**). Any key with value **nil** is not considered part oft he table. Conversely, any key that is not part of a table has an a ssociated value **nil**. [`View online doc`](https://www.lua.org/manual/5.4/manual.html#2) | [`View local doc`](command:extension.lua.doc?["en-us/54/manual.html/2"]) 14 | 15 | ---@class string: any 16 | 17 | ---@class void 18 | 19 | ---@class userdata: any @The type `userdata` is provided to allow arbitrary C data to be stored in Lua variables. A `userdata` value represents a block of raw memory. There are two kinds of `userdata`: `full userdata`, which is an object with a block of memory managed by Lua, and `light userdata`, which is simply a C pointer value. Userdata has no predefined operations in Lua, except assignment and identity test. By using metatables, the programmer can define operations for `full userdata` values. Userdata values cannot be created or modified in Lua, only through the C API. This guarantees the integrity of data owned by the host program and C libraries. [`View online doc`](https://www.lua.org/manual/5.4/manual.html#2) | [`View local doc`](command:extension.lua.doc?["en-us/54/manual.html/2"]) 20 | 21 | ---@class lightuserdata: userdata 22 | 23 | ---@class function: any @Lua can call (and manipulate) functions written in Lua and functions written in C. Both are represented by the type *function*. 24 | -------------------------------------------------------------------------------- /luahelper-vscode/server/meta/template/ffi.lua: -------------------------------------------------------------------------------- 1 | ---@class ffi.namespace: table 2 | 3 | ---@class ffi.cdecl: string 4 | ---@class ffi.ctype: userdata 5 | 6 | ---@class ffi.cdata: userdata 7 | ---@alias ffi.ct ffi.cdecl|ffi.ctype|ffi.cdata 8 | ---@class ffi.cb: userdata 9 | local cb 10 | ---@class ffi.VLA: userdata 11 | ---@class ffi.VLS: userdata 12 | 13 | ---@version JIT 14 | ---@class ffilib 15 | ---@field C ffi.namespace 16 | ---@field os string 17 | ---@field arch string 18 | local ffi = {} 19 | 20 | ---@param def string 21 | function ffi.cdef(def) end 22 | 23 | ---@param name string 24 | ---@param global? boolean 25 | ---@return ffi.namespace clib 26 | function ffi.load(name, global) end 27 | 28 | ---@param ct ffi.ct 29 | ---@param nelem? integer 30 | ---@param init? any 31 | ---@return ffi.cdata cdata 32 | function ffi.new(ct, nelem, init, ...) end 33 | 34 | ---@param nelem? integer 35 | ---@param init? any 36 | ---@return ffi.cdata cdata 37 | function ctype(nelem, init, ...) end 38 | 39 | ---@param ct ffi.ct 40 | ---@return ffi.ctype ctype 41 | function ffi.typeof(ct) end 42 | 43 | ---@param ct ffi.ct 44 | ---@param init any 45 | ---@return ffi.cdata cdata 46 | function ffi.cast(ct, init) end 47 | 48 | ---@param ct ffi.ct 49 | ---@param metatable table 50 | ---@return ffi.ctype ctype 51 | function ffi.metatype(ct, metatable) end 52 | 53 | ---@param cdata ffi.cdata 54 | ---@param finalizer function 55 | ---@return ffi.cdata cdata 56 | function ffi.gc(cdata, finalizer) end 57 | 58 | ---@param ct ffi.ct 59 | ---@param nelem? integer 60 | ---@return integer|nil size 61 | function ffi.sizeof(ct, nelem) end 62 | 63 | ---@param ct ffi.ct 64 | ---@return integer align 65 | function ffi.alignof(ct) end 66 | 67 | ---@param ct ffi.ct 68 | ---@param field string 69 | ---@return integer ofs 70 | ---@return integer? bpos 71 | ---@return integer? bsize 72 | function ffi.offsetof(ct, field) end 73 | 74 | ---@param ct ffi.ct 75 | ---@param obj any 76 | ---@return boolean status 77 | function ffi.istype(ct, obj) end 78 | 79 | ---@param newerr? integer 80 | ---@return integer err 81 | function ffi.errno(newerr) end 82 | 83 | ---@param ptr any 84 | ---@param len? integer 85 | ---@return string str 86 | function ffi.string(ptr, len) end 87 | 88 | ---@overload fun(dst: any, str: string) 89 | ---@param dst any 90 | ---@param src any 91 | ---@param len integer 92 | function ffi.copy(dst, src, len) end 93 | 94 | ---@param dst any 95 | ---@param len integer 96 | ---@param c? any 97 | function ffi.fill(dst, len, c) end 98 | 99 | ---@param param string 100 | ---@return boolean status 101 | function ffi.abi(param) end 102 | 103 | function cb:free() end 104 | 105 | ---@param func function 106 | function cb:set(func) end 107 | -------------------------------------------------------------------------------- /luahelper-vscode/server/meta/template/jit.lua: -------------------------------------------------------------------------------- 1 | ---@version JIT 2 | ---@class jitlib 3 | ---@field version string 4 | ---@field version_num number 5 | ---@field os string 6 | ---@field arch string 7 | jit = {} 8 | 9 | ---@overload fun() 10 | ---@param func function|boolean 11 | ---@param recursive? boolean 12 | function jit.on(func, recursive) end 13 | 14 | ---@overload fun() 15 | ---@param func function|boolean 16 | ---@param recursive? boolean 17 | function jit.off(func, recursive) end 18 | 19 | ---@overload fun() 20 | ---@overload fun(tr: number) 21 | ---@param func function|boolean 22 | ---@param recursive? boolean 23 | function jit.flush(func, recursive) end 24 | 25 | ---@return boolean status 26 | ---@return ... 27 | function jit.status() end 28 | -------------------------------------------------------------------------------- /luahelper-vscode/server/win32/lua-format.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent/LuaHelper/15c9fac58a73c6f780257c81664a03b52d941f9d/luahelper-vscode/server/win32/lua-format.exe -------------------------------------------------------------------------------- /luahelper-vscode/snippets/snippets.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | } -------------------------------------------------------------------------------- /luahelper-vscode/src/common/logManager.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode'; 2 | 3 | export class DebugLogger { 4 | private static Ainfo; 5 | private static Dinfo; 6 | 7 | public static init() { 8 | DebugLogger.Ainfo = vscode.window.createOutputChannel("Adapter/log"); 9 | // DebugLogger.Ainfo.show(); 10 | 11 | DebugLogger.Dinfo = vscode.window.createOutputChannel("Debugger/log"); 12 | // DebugLogger.Dinfo.show(); 13 | DebugLogger.Dinfo.appendLine("LuaHelper initializing..."); 14 | } 15 | 16 | public static DebuggerInfo(str: string) { 17 | if (str != "" && str != null) { 18 | DebugLogger.Dinfo.appendLine(str); 19 | } 20 | } 21 | public static AdapterInfo(str: string) { 22 | if (str != "" && str != null) { 23 | DebugLogger.Ainfo.appendLine(str); 24 | } 25 | } 26 | 27 | public static showTips(str:string , level?:number){ 28 | if(level === 2 ){ 29 | vscode.window.showErrorMessage(str); 30 | }else if(level === 1 ){ 31 | vscode.window.showWarningMessage(str); 32 | }else{ 33 | vscode.window.showInformationMessage(str); 34 | } 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /luahelper-vscode/src/common/threadManager.ts: -------------------------------------------------------------------------------- 1 | // import { DebugLogger } from './logManager'; 2 | 3 | export class ThreadManager { 4 | static THREAD_ID_COUNTER = 0; // 线程计数器 5 | static NEXT_THREAD_ID = 0; // 指示下一个待分配 thread id 6 | private _CUR_THREAD_ID; // 当前线程号,从 0 开始 7 | get CUR_THREAD_ID(){ 8 | return this._CUR_THREAD_ID; 9 | } 10 | 11 | public constructor() { 12 | this._CUR_THREAD_ID = ThreadManager.NEXT_THREAD_ID; 13 | ThreadManager.NEXT_THREAD_ID ++; 14 | ThreadManager.THREAD_ID_COUNTER ++; 15 | } 16 | 17 | // 析构函数 如果线程数为0, 待分配线程号也置0 18 | public destructor() { 19 | ThreadManager.THREAD_ID_COUNTER--; 20 | if(ThreadManager.THREAD_ID_COUNTER === 0){ 21 | ThreadManager.NEXT_THREAD_ID = 0; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /luahelper-vscode/src/debug/breakPoint.ts: -------------------------------------------------------------------------------- 1 | import { DebugProtocol } from 'vscode-debugprotocol'; 2 | 3 | enum BreakpointType { 4 | conditionBreakpoint = 0, 5 | logPoint, 6 | lineBreakpoint 7 | } 8 | 9 | export class LineBreakpoint implements DebugProtocol.Breakpoint { 10 | verified: boolean; 11 | type: BreakpointType; 12 | line: number; 13 | constructor(verified: boolean, line: number, id: number, column?: number) { 14 | this.verified = verified; 15 | this.type = BreakpointType.lineBreakpoint; 16 | this.line = line; 17 | } 18 | } 19 | 20 | export class ConditionBreakpoint implements DebugProtocol.Breakpoint, DebugProtocol.SourceBreakpoint { 21 | verified: boolean; 22 | type: BreakpointType; 23 | line: number; 24 | condition: string; 25 | constructor(verified: boolean, line: number, condition: string, id: number) { 26 | this.verified = verified; 27 | this.type = BreakpointType.conditionBreakpoint; 28 | this.line = line; 29 | this.condition = condition; 30 | } 31 | } 32 | 33 | export class LogPoint implements DebugProtocol.Breakpoint, DebugProtocol.SourceBreakpoint { 34 | verified: boolean; 35 | type: BreakpointType; 36 | line: number; 37 | logMessage: string; 38 | constructor(verified: boolean, line: number, logMessage: string, id: number) { 39 | this.verified = verified; 40 | this.type = BreakpointType.logPoint; 41 | this.line = line; 42 | this.logMessage = logMessage; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /luahelper-vscode/src/debug/debugAdapter.ts: -------------------------------------------------------------------------------- 1 | import { LuaDebugSession } from './luaDebug'; 2 | 3 | LuaDebugSession.run(LuaDebugSession); 4 | -------------------------------------------------------------------------------- /luahelper-vscode/src/languageConfiguration.ts: -------------------------------------------------------------------------------- 1 | import { LanguageConfiguration, IndentAction } from "vscode"; 2 | 3 | export class LuaLanguageConfiguration implements LanguageConfiguration { 4 | public onEnterRules = [ 5 | { 6 | action: { indentAction: IndentAction.None, appendText: "---@" }, 7 | beforeText: /( *---@class)|( *---@field)|( *---@param)|( *---@return)/, 8 | } 9 | ]; 10 | 11 | public wordPattern = /((?<=')[^']+(?='))|((?<=")[^"]+(?="))|(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\s]+)/g; 12 | } -------------------------------------------------------------------------------- /luahelper-vscode/src/notifications.ts: -------------------------------------------------------------------------------- 1 | import * as vscode from 'vscode'; 2 | 3 | export interface AnnotatorParams { 4 | uri: string; 5 | } 6 | 7 | export enum AnnotatorType { 8 | GlobalVar, 9 | GlobalFunc, 10 | AnnotateType, 11 | } 12 | 13 | export interface IAnnotator { 14 | uri: string; 15 | ranges: vscode.Range[]; 16 | annotatorType: AnnotatorType; 17 | } 18 | 19 | // 启动插件加载工程所花费的时间 20 | export interface IProgressReport { 21 | state: number; // 通知的状态,0为加载目录, 1为加载文件中,2为加载完毕 22 | text: string; // 显示的字符串 23 | } 24 | 25 | export interface GetOnlineParams { 26 | Req: number;// 参数无意义 27 | } 28 | 29 | 30 | export interface GetOnlineReturn { 31 | Num: number;// 所有在线的人数 32 | } -------------------------------------------------------------------------------- /luahelper-vscode/src/onlinePeople.ts: -------------------------------------------------------------------------------- 1 | import { window, StatusBarItem, StatusBarAlignment } from 'vscode'; 2 | import { LanguageClient } from 'vscode-languageclient/node'; 3 | import * as notifications from "./notifications"; 4 | import * as vscode from 'vscode'; 5 | 6 | let statusBar: StatusBarItem; 7 | 8 | export class OnlinePeople { 9 | private timeoutToReqAnn: NodeJS.Timer; 10 | 11 | public Start(client: LanguageClient) { 12 | if (!statusBar) { 13 | statusBar = window.createStatusBarItem(StatusBarAlignment.Right); 14 | } 15 | 16 | if (this.timeoutToReqAnn) { 17 | clearInterval(this.timeoutToReqAnn); 18 | } 19 | 20 | sendRequest(statusBar, client); 21 | 22 | // 每分钟触发一次 23 | this.timeoutToReqAnn = setInterval(function () { 24 | sendRequest(statusBar, client); 25 | }, 60000); 26 | } 27 | 28 | 29 | // 销毁对象和自由资源 30 | dispose() { 31 | statusBar.dispose(); 32 | if (this.timeoutToReqAnn) { 33 | clearInterval(this.timeoutToReqAnn); 34 | } 35 | } 36 | } 37 | 38 | function sendRequest(statusBar: StatusBarItem, client: LanguageClient) { 39 | let params: notifications.GetOnlineParams = { Req: 0 }; 40 | client.sendRequest("luahelper/getOnlineReq", params).then(onelineReturn => { 41 | let showConfig = vscode.workspace.getConfiguration("luahelper.base", null).get("showOnline"); 42 | var openFlag = false; 43 | if (showConfig !== undefined) { 44 | openFlag = showConfig; 45 | } 46 | 47 | if (openFlag === true) { 48 | if (onelineReturn.Num === 0) { 49 | statusBar.text = "LuaHelper"; 50 | statusBar.tooltip = "LuaHelper"; 51 | statusBar.show(); 52 | } else { 53 | if (vscode.env.language === "zh-cn" || vscode.env.language === "zh-tw") { 54 | statusBar.text = "LuaHelper 在线人数 : " + onelineReturn.Num; 55 | statusBar.tooltip = "LuaHelper online People: " + onelineReturn.Num; 56 | } else { 57 | statusBar.text = "LuaHelper : " + onelineReturn.Num; 58 | statusBar.tooltip = "LuaHelper Online People: " + onelineReturn.Num; 59 | } 60 | statusBar.show(); 61 | } 62 | } else { 63 | statusBar.text = "LuaHelper"; 64 | statusBar.tooltip = "LuaHelper"; 65 | statusBar.show(); 66 | } 67 | }); 68 | } 69 | -------------------------------------------------------------------------------- /luahelper-vscode/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es6", 5 | "outDir": "out", 6 | "lib": [ 7 | "es6" 8 | ], 9 | "skipLibCheck": true, 10 | "sourceMap": true, 11 | "rootDir": "src", 12 | "noImplicitAny": false, 13 | /* Strict Type-Checking Option */ 14 | "strict": false, /* enable all strict type-checking options */ 15 | /* Additional Checks */ 16 | "noUnusedLocals": true /* Report errors on unused locals. */ 17 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 18 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 19 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 20 | }, 21 | "exclude": [ 22 | "node_modules", 23 | ".vscode-test" 24 | ] 25 | } -------------------------------------------------------------------------------- /luahelper-vscode/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "no-string-throw": true, 4 | "no-unused-expression": true, 5 | "no-duplicate-variable": true, 6 | "curly": true, 7 | "class-name": true, 8 | "semicolon": [ 9 | true, 10 | "always" 11 | ], 12 | "triple-equals": true 13 | }, 14 | "defaultSeverity": "warning" 15 | } -------------------------------------------------------------------------------- /luahelper-vscode/vsc-extension-quickstart.md: -------------------------------------------------------------------------------- 1 | # Welcome to your VS Code Extension 2 | 3 | ## What's in the folder 4 | * This folder contains all of the files necessary for your extension. 5 | * `package.json` - this is the manifest file in which you declare your extension and command. 6 | The sample plugin registers a command and defines its title and command name. With this information 7 | VS Code can show the command in the command palette. It doesn’t yet need to load the plugin. 8 | * `src/extension.ts` - this is the main file where you will provide the implementation of your command. 9 | The file exports one function, `activate`, which is called the very first time your extension is 10 | activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`. 11 | We pass the function containing the implementation of the command as the second parameter to 12 | `registerCommand`. 13 | 14 | ## Get up and running straight away 15 | * Press `F5` to open a new window with your extension loaded. 16 | * Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`. 17 | * Set breakpoints in your code inside `src/extension.ts` to debug your extension. 18 | * Find output from your extension in the debug console. 19 | 20 | ## Make changes 21 | * You can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`. 22 | * You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes. 23 | 24 | ## Explore the API 25 | * You can open the full set of our API when you open the file `node_modules/vscode/vscode.d.ts`. 26 | 27 | ## Run tests 28 | * Open the debug viewlet (`Ctrl+Shift+D` or `Cmd+Shift+D` on Mac) and from the launch configuration dropdown pick `Launch Tests`. 29 | * Press `F5` to run the tests in a new window with your extension loaded. 30 | * See the output of the test result in the debug console. 31 | * Make changes to `test/extension.test.ts` or create new test files inside the `test` folder. 32 | * By convention, the test runner will only consider files matching the name pattern `**.test.ts`. 33 | * You can create folders inside the `test` folder to structure your tests any way you want. 34 | --------------------------------------------------------------------------------