Giter Site home page Giter Site logo

emmyluaanalyzer's Introduction

EmmyLuaAnalyzer

Introduction

The EmmyLuaAnalyzer project is a static analyzer and language service for the Lua language implemented in C#. It mainly consists of two parts:

  1. Lua code analysis core that supports EmmyLua Doc. It is an independent Lua code analysis library that can be used to analyze Lua code, generate abstract syntax trees, provide semantic analysis, and other functions.
  2. EmmyLua language service, which is a Lua language server based on the above code analysis core. It provides the main language service functions, including code hints, code completion, refactoring, and other features.

Features

  • Supports mainstream Lua versions, including Lua 5.1, Lua 5.2, Lua 5.3, Lua 5.4, LuaJIT.
  • Supports EmmyLua Doc comments and is compatible with the Doc format of Lua-Language-Server (abbreviated as LuaLs).
  • Supports all language service features (not all are supported yet, currently supports the main ones that will be used).
  • Formatting is not supported yet (EmmyLuaCodeStyle, which I also wrote, has its own independent language service).

Documentation

  • TODO

Usage

Use EmmyLuaAnalyzer's analysis core through nuget

TODO

Use EmmyLuaAnalyzer's language service through the VSCode plugin

You can currently use EmmyLuaAnalyzer's language service by checking Use EmmyLuaAnalyzer in VSCode-EmmyLua.

Testing

Currently in beta, everyone is welcome to test and make suggestions. There is still a lot of work in progress and needs to be improved.

LICENSE

MIT

emmyluaanalyzer's People

Contributors

cppcxy avatar whitecostume avatar xuhuanzy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

emmyluaanalyzer's Issues

Possible improvements to analyzer

I gave the new EmmyLuaAnalyzer a whirl and here's some things I found:

Bugs

  • Hover state does not show class fields
    image

  • "Read more" arrow always shows, even with subwindow is empty
    Screenshot 2024-05-02 at 20 42 20

  • ---@deprecated does not appear in hover. Calls to deprecated methods should be striken().
    Screenshot 2024-05-02 at 20 46 22

  • Clicking EmmyLua in status bar results in "emmy.stopServer not found" error message.
    Screenshot 2024-05-02 at 20 50 45

  • Putting an invalid path (e.g. "fakedir" into workspace.library in emmyrc.json caused crash on startup. If you change/add this mid-session EmmyLua becomes non-responsive (and stop is broken).
    Screenshot 2024-05-02 at 21 03 00

  • #12
    image
    Screenshot 2024-05-02 at 21 17 09

  • Completions for ---@ should should only be type annotation related [@class,@param,@return,etc]
    Screenshot 2024-05-02 at 21 17 58

  • #13
    Screenshot 2024-05-02 at 21 21 09

  • Duplicate functions (with different params) inside a ---@meta are not suggested as multiple options (first wins?)
    Screenshot 2024-05-02 at 21 25 38

  • Types on ... are not properly checked and ...? is displayed as... in function signatures.
    Screenshot 2024-05-02 at 21 30 08

  • Class field descriptions do not appear as part of extended suggestion, but are present in the hover window.
    Screenshot 2024-05-02 at 21 47 37

  • #14
    Screenshot 2024-05-02 at 21 50 39

  • Assignments to optional returns (e.g. string? or string|nil do not preserve their nullability in types. This should be _File? or _File?.
    Screenshot 2024-05-02 at 21 56 20

  • workspace.library in .emmyrc.json only works with relative paths. 0.6.15 changelog here says:

    Now all places where paths can be filled support relative paths, absolute paths, and ${workspaceFolder} to represent the workspace, ~ to represent the user directory
    Tildes do not expanded properly (~/proj becomes /proj). Absolute paths are wrongly concatenated as paths under workspaceFolder. ${workspaceFolder}/../whatever works as designed.

  • Assignments should preserve transitive comment annotations.
    Screenshot 2024-05-02 at 22 51 56

  • Quote handling for @alias types is not right (duplicated double quotes): "". Dunno if the EmmyLua types need to updated. Here is how LuaLS defines them for reference.
    Screenshot 2024-05-02 at 23 02 12
    Screenshot 2024-05-02 at 23 07 28

Settings

  • Please increase the default for workspace.preloadFileSize. Maybe 5120000?

  • .emmyrc.json: It'd be sweet to have a JSON schema. Then if you set "$schema" to the url users get config validation for free in VSCode. Are you intending to support .laurc.json as well? You're close enough to the LuaLS .luarc.json schema that I think you could implement proper superset of what it supports.

  • .emmyrc.json: Please add support for runtime.nonstandardSymbol. Here's what I use for Playdate Development: ["+=", "-=", "*=", "/=", "//=", "%=", "<<=", ">>=", "&=", "|=", "^="]

Future suggested capabilities

  • Add colors/tokenize type/names inside comment annotations. fun(), | and : get fancy colorization, but everything else is just a comment (green).
    Screenshot 2024-05-02 at 23 28 49

  • Analyzer should warn on duplicate assignments (unless inside ---@meta file)
    Screenshot 2024-05-02 at 22 42 11

  • Analyzer should warn when assigning incorrect types.
    Screenshot 2024-05-02 at 22 38 35

  • Analyzer should warn/error when nullable types are not checked for nil before calling. E.g. err:len() should have warning.
    Screenshot 2024-05-02 at 21 59 49

  • Analyzer should warn when assigning to constants (this will fail at runtime)
    Screenshot 2024-05-02 at 22 47 50


Steps to reproduce:

  1. Create a folder with an .emmyrc.json:
{
    "workspace": {
        "preloadFileSize": 5120000,
        "library": [
            "../playdate-luacats"
        ]
    }
}
  1. Checkout https://github.com/notpeter/playdate-luacats/
  2. Profit?

索引查找bug

---@field a number
---@field b number
local A = {
    a = 1,
    aa = 2
}

function A:print()

end

---@generic V
---@param super any
---@param name `V`
---@return V
function inherit(super, name)
    local newClass = {}
    newClass.__index = newClass
    return setmetatable(newClass, super)
end

---@class B : A
local B = inherit(A, "B")

function B:print()
    local sf = self
    sf.a = 10
end

如上代码,期望倒数第二行sf.a可以查到找基类A中a字段的定义,基类A中查找field a的引用可以查找到sf.a=10的代码行。
目前测试下来,a的定义和引用极大概率查找不成功,小概率成功

插件刷新有问题

截屏2024-05-23 10 37 40

这种提示刷新有问题, 就算改完, 在git上提交了, 依旧会出现.
点了提示后会跳到git提交前的文件, 只有关了vscode, 重启服务才能解决

:语法调用导致泛型模板类型诊断错误问题

local A = {
a = 1,
aa = 2
}

---@generic T
---@param sf T
---@param ina number
---@return T
function A.new(sf, ina)
end

local a = A:new(3)
local b = A.new(A, 3)

以上代码倒数第二行A:new(3) 参数3将会错误的推断为A.new中的第一个参数,并且a类型返回推断错误

BUG Report

Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'path1')
at System.ArgumentNullException.Throw(String paramName)
at System.IO.Path.Combine(String path1, String path2)
at EmmyLua.CodeAnalysis.Workspace.Module.ModuleGraph.AddPackageRoot(String packageRoot) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua\CodeAnalysis\Workspace\Module\ModuleGraph.cs:line 42
at EmmyLua.CodeAnalysis.Workspace.LuaWorkspace.LoadMainWorkspace(String workspace) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua\CodeAnalysis\Workspace\LuaWorkspace.cs:line 119
at EmmyLua.LanguageServer.Server.ServerContext.StartServer(String workspacePath) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua.LanguageServer\Server\ServerContext.cs:line 43
at Program.<>c__DisplayClass0_1.<

$>b__4(ILanguageServer server, CancellationToken _) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua.LanguageServer\LanguageServer.cs:line 102
at OmniSharp.Extensions.LanguageServer.Server.LanguageServer.b__80_0(OnLanguageServerStartedDelegate handler, CancellationToken ct)
at OmniSharp.Extensions.LanguageServer.Protocol.LanguageProtocolEventingHelper.<>c__DisplayClass0_12.<Run>b__2(CancellationToken ct) at System.Reactive.Linq.QueryLanguage.StartAsyncImpl(Func2 actionAsync, Value& options)
--- End of stack trace from previous location ---
at OmniSharp.Extensions.LanguageServer.Server.LanguageServer.Initialize(CancellationToken token)
at OmniSharp.Extensions.LanguageServer.Server.LanguageServer.From(LanguageServerOptions options, IServiceProvider outerServiceProvider, CancellationToken cancellationToken)
at Program.$(String[] args) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua.LanguageServer\LanguageServer.cs:line 37
at Program.(String[] args)
[Info - 09:50:00] Connection to server got closed. Server will restart.
true
[Error - 09:50:00] Server process exited with code 3762504530.
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'path1')
at System.ArgumentNullException.Throw(String paramName)
at System.IO.Path.Combine(String path1, String path2)
at EmmyLua.CodeAnalysis.Workspace.Module.ModuleGraph.AddPackageRoot(String packageRoot) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua\CodeAnalysis\Workspace\Module\ModuleGraph.cs:line 42
at EmmyLua.CodeAnalysis.Workspace.LuaWorkspace.LoadMainWorkspace(String workspace) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua\CodeAnalysis\Workspace\LuaWorkspace.cs:line 119
at EmmyLua.LanguageServer.Server.ServerContext.StartServer(String workspacePath) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua.LanguageServer\Server\ServerContext.cs:line 43
at Program.<>c__DisplayClass0_1.<$>b__4(ILanguageServer server, CancellationToken _) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua.LanguageServer\LanguageServer.cs:line 102
at OmniSharp.Extensions.LanguageServer.Server.LanguageServer.b__80_0(OnLanguageServerStartedDelegate handler, CancellationToken ct)
at OmniSharp.Extensions.LanguageServer.Protocol.LanguageProtocolEventingHelper.<>c__DisplayClass0_12.<Run>b__2(CancellationToken ct) at System.Reactive.Linq.QueryLanguage.StartAsyncImpl(Func2 actionAsync, Value& options)
--- End of stack trace from previous location ---
at OmniSharp.Extensions.LanguageServer.Server.LanguageServer.Initialize(CancellationToken token)
at OmniSharp.Extensions.LanguageServer.Server.LanguageServer.From(LanguageServerOptions options, IServiceProvider outerServiceProvider, CancellationToken cancellationToken)
at Program.$(String[] args) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua.LanguageServer\LanguageServer.cs:line 37
at Program.(String[] args)
[Info - 09:50:02] Connection to server got closed. Server will restart.
true
[Error - 09:50:02] Server process exited with code 3762504530.
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'path1')
at System.ArgumentNullException.Throw(String paramName)
at System.IO.Path.Combine(String path1, String path2)
at EmmyLua.CodeAnalysis.Workspace.Module.ModuleGraph.AddPackageRoot(String packageRoot) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua\CodeAnalysis\Workspace\Module\ModuleGraph.cs:line 42
at EmmyLua.CodeAnalysis.Workspace.LuaWorkspace.LoadMainWorkspace(String workspace) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua\CodeAnalysis\Workspace\LuaWorkspace.cs:line 119
at EmmyLua.LanguageServer.Server.ServerContext.StartServer(String workspacePath) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua.LanguageServer\Server\ServerContext.cs:line 43
at Program.<>c__DisplayClass0_1.<$>b__4(ILanguageServer server, CancellationToken _) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua.LanguageServer\LanguageServer.cs:line 102
at OmniSharp.Extensions.LanguageServer.Server.LanguageServer.b__80_0(OnLanguageServerStartedDelegate handler, CancellationToken ct)
at OmniSharp.Extensions.LanguageServer.Protocol.LanguageProtocolEventingHelper.<>c__DisplayClass0_12.<Run>b__2(CancellationToken ct) at System.Reactive.Linq.QueryLanguage.StartAsyncImpl(Func2 actionAsync, Value& options)
--- End of stack trace from previous location ---
at OmniSharp.Extensions.LanguageServer.Server.LanguageServer.Initialize(CancellationToken token)
at OmniSharp.Extensions.LanguageServer.Server.LanguageServer.From(LanguageServerOptions options, IServiceProvider outerServiceProvider, CancellationToken cancellationToken)
at Program.$(String[] args) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua.LanguageServer\LanguageServer.cs:line 37
at Program.(String[] args)
[Info - 09:50:03] Connection to server got closed. Server will restart.
true
[Error - 09:50:03] Server process exited with code 3762504530.
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'path1')
at System.ArgumentNullException.Throw(String paramName)
at System.IO.Path.Combine(String path1, String path2)
at EmmyLua.CodeAnalysis.Workspace.Module.ModuleGraph.AddPackageRoot(String packageRoot) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua\CodeAnalysis\Workspace\Module\ModuleGraph.cs:line 42
at EmmyLua.CodeAnalysis.Workspace.LuaWorkspace.LoadMainWorkspace(String workspace) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua\CodeAnalysis\Workspace\LuaWorkspace.cs:line 119
at EmmyLua.LanguageServer.Server.ServerContext.StartServer(String workspacePath) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua.LanguageServer\Server\ServerContext.cs:line 43
at Program.<>c__DisplayClass0_1.<$>b__4(ILanguageServer server, CancellationToken _) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua.LanguageServer\LanguageServer.cs:line 102
at OmniSharp.Extensions.LanguageServer.Server.LanguageServer.b__80_0(OnLanguageServerStartedDelegate handler, CancellationToken ct)
at OmniSharp.Extensions.LanguageServer.Protocol.LanguageProtocolEventingHelper.<>c__DisplayClass0_12.<Run>b__2(CancellationToken ct) at System.Reactive.Linq.QueryLanguage.StartAsyncImpl(Func2 actionAsync, Value& options)
--- End of stack trace from previous location ---
at OmniSharp.Extensions.LanguageServer.Server.LanguageServer.Initialize(CancellationToken token)
at OmniSharp.Extensions.LanguageServer.Server.LanguageServer.From(LanguageServerOptions options, IServiceProvider outerServiceProvider, CancellationToken cancellationToken)
at Program.$(String[] args) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua.LanguageServer\LanguageServer.cs:line 37
at Program.(String[] args)
[Info - 09:50:03] Connection to server got closed. Server will restart.
true
[Error - 09:50:03] Server process exited with code 3762504530.
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'path1')
at System.ArgumentNullException.Throw(String paramName)
at System.IO.Path.Combine(String path1, String path2)
at EmmyLua.CodeAnalysis.Workspace.Module.ModuleGraph.AddPackageRoot(String packageRoot) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua\CodeAnalysis\Workspace\Module\ModuleGraph.cs:line 42
at EmmyLua.CodeAnalysis.Workspace.LuaWorkspace.LoadMainWorkspace(String workspace) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua\CodeAnalysis\Workspace\LuaWorkspace.cs:line 119
at EmmyLua.LanguageServer.Server.ServerContext.StartServer(String workspacePath) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua.LanguageServer\Server\ServerContext.cs:line 43
at Program.<>c__DisplayClass0_1.<$>b__4(ILanguageServer server, CancellationToken _) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua.LanguageServer\LanguageServer.cs:line 102
at OmniSharp.Extensions.LanguageServer.Server.LanguageServer.b__80_0(OnLanguageServerStartedDelegate handler, CancellationToken ct)
at OmniSharp.Extensions.LanguageServer.Protocol.LanguageProtocolEventingHelper.<>c__DisplayClass0_12.<Run>b__2(CancellationToken ct) at System.Reactive.Linq.QueryLanguage.StartAsyncImpl(Func2 actionAsync, Value& options)
--- End of stack trace from previous location ---
at OmniSharp.Extensions.LanguageServer.Server.LanguageServer.Initialize(CancellationToken token)
at OmniSharp.Extensions.LanguageServer.Server.LanguageServer.From(LanguageServerOptions options, IServiceProvider outerServiceProvider, CancellationToken cancellationToken)
at Program.$(String[] args) in D:\a\EmmyLuaAnalyzer\EmmyLuaAnalyzer\EmmyLua.LanguageServer\LanguageServer.cs:line 37
at Program.(String[] args)
[Error - 09:50:04] The EmmyLua plugin for vscode. server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.
[Error - 09:50:04] Server process exited with code 3762504530.

全局变量分析问题

程序启动时会声明

---@type UIManager
UIMgr = require("UIManager").New()

在程序关闭时,会在特定方法里执行

UIMgr = nil

一旦写了后面的赋值代码后, 就会提示UIMgr是nil

截屏2024-05-27 20 10 57 截屏2024-05-27 20 10 47

代码提示问题

旧版本 使用

---@class AAA
local AAA = Class("AAA")

local a = AAA()

可以将a识别为AAA这个类型, 新版本不行, 而且没发提示__call

模板类型推断问题

local A = {
a = 1,
aa = 2
}

---@class B
local B = {
}

---@generic T : B
---@param base? T
---@return T
function A:GetBB(base)
end

local x = A:GetBB()
local y = A:GetBB(B)

如上代码,期望倒数第二行x的类型推断为B,实际推断为T

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.