Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

對於同一個 working dictionary,無法跨文件跳轉到自定義的 function #59

Closed
mosdeo opened this issue Mar 6, 2020 · 3 comments

Comments

@mosdeo
Copy link

mosdeo commented Mar 6, 2020

Describe the bug
定義跳轉功能的問題

  • 可以跳轉到 lua 原生 function,例如 require()
  • 可以跳轉到同一個文件內的自定義 function
  • 不能跳轉到不同文件內的自定義 function(在同一個 working dictionary)

To Reproduce
Steps to reproduce the behavior:

  1. 在自定義 function 上按右鍵,點「移至定義」
  2. 顯示找不到 XXX() 的定義,但 XXX() 是宣告在同一個 working dictionary 甚至是同一個 dictionary 內的 *.lua。

Expected behavior
如同跳轉到 Lua 原生 function 一樣,游標自動到達定義處。

Screenshots
image

Desktop (please complete the following information):

  • OS: macOS
  • Visual Studio

版本: 1.42.1
日期: 2020-02-11T14:44:27.652Z
Electron: 6.1.6
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Darwin x64 19.3.0

  • LuaPanda Version: 3.1.0
  • Framework: Nakama

Additional context

Lua Version: 5.3.5

這裡提及的 *.lua 皆能在 VSCode 上被辨認出正確格式:

  • 訊息欄有LuaPanda👍圖標
  • 右下角有image圖示
@stuartwang
Copy link
Collaborator

stuartwang commented Mar 7, 2020

非常感谢这么详细的 issue。 从状态栏我看到Luapanda已经正确启动了,根据描述能做同文件的跳转。

关于定义跳转部分,我们预设的逻辑是:
当用户进行定义跳转时,首先会去查阅当前文件中是否有这个定义,如果没有就查询它require的文件。按照require树向上查找。如果最后还是找不到,就会在工程中所有lua文件中查询。
我做了一个demo测试了一下同 working dictionary 跨文件的跳转,demo中是可以的(可能是demo代码简单的原因)。

但是有几种情况可能会影响查询:

  1. 假如A文件中有一个function定义,B文件中使用了这个function。在B文件中做定义跳转时,若A或B文件有语法错误,则可能查不到定义。原因是对于语法错误的文件, parser 没有生成AST,也无法做符号分析,造成查询失败。

  2. 对于一些稍复杂的逻辑中的定义, 比如嵌套的函数调用等,可能查询失败
    比如 table.insert(t, string.sub(s, j+1, i-1))
    原因是符号建立和查询是一个大的递归操作,可能我们其中有些逻辑没有处理到或是有bug,造成了符号没有按预期被创建,或是被查询到。

  3. lua是一种弱类型语言,变量类型/和全局变量的定义都很灵活。静态分析可能难以得出准确的结果,也会影响查询的准确度。

关于定义跳转和补全,其实我们是搭了一个框架,用户操作时插件就会按照框架中的逻辑递归查找,通常我们也需要借助对具体案例的调试才能够得到确切的原因。我们会逐步完善这个框架。如果遇到定义查找和代码补全的问题希望解决,可以抽象成一两个文件的简单用例(纯lua就行,不要求能运行起来,但不能有语法错误)发给我们。这样我们可以对具体案例进行分析。

再次感谢详细的 issue

@mosdeo
Copy link
Author

mosdeo commented Mar 7, 2020

謝謝你的詳細回覆。這是根據實際目錄結構、函式結構,做出的測試案例。在我的環境上可以重現我在 Describe the bug 描述的「兩個可以,一個不能」
https://github.com/mosdeo/FailCase_LuaPandaCanNotGoToDefinition

@stuartwang
Copy link
Collaborator

非常感谢,我看到用例了。 OpcodeX.swap_echo_return 没有办法正确跳转。
应该是 function/file 的返回值我们没有处理好,我们会修复一下~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants