Giter VIP home page Giter VIP logo

Comments (4)

fesily avatar fesily commented on September 25, 2024

script/vm/compiler.lua compileLocal

    if source.parent.type == 'funcargs' and not hasMarkDoc and not hasMarkParam then
        local func = source.parent.parent
        -- local call ---@type fun(f: fun(x: number));call(function (x) end) --> x -> number
        local funcNode = vm.compileNode(func)
        local hasDocArg
        for n in funcNode:eachObject() do
            if n.type == 'doc.type.function' then
                for index, arg in ipairs(n.args) do
                    if func.args[index] == source then
                        local argNode = vm.compileNode(arg)
                        for an in argNode:eachObject() do
                            if an.type ~= 'doc.generic.name' then
                                vm.setNode(source, an)
                            end
                        end
                        hasDocArg = true
                    end
                end
            end
        end
        if not hasDocArg then
            local refs = vm.getRefs(source.parent.parent)
            local findCall
            if refs then
                for i, ref in ipairs(refs) do
                    if ref.parent.type == 'call' then
                        findCall = ref.parent
                        break
                    end
                end
            end
            if findCall then
                local index
                for i, arg in ipairs(source.parent) do
                    if arg == source then
                        index = i
                        break
                    end
                end
                if index then
                    hasDocArg = true
                    local callerArg = findCall.args[index]
                    vm.setNode(source, vm.compileNode(callerArg))
                end
            end
        end
        if not hasDocArg then
            vm.setNode(source, vm.declareGlobal('type', 'any'))
        end
    end

It's worked

from lua-language-server.

sumneko avatar sumneko commented on September 25, 2024

vm.getRefs may very slow

from lua-language-server.

fesily avatar fesily commented on September 25, 2024

It is indeed slow, so one should limit the search in which way.
I think first just find the first valid function call.

from lua-language-server.

fesily avatar fesily commented on September 25, 2024

Limiting types to local variables,maybe better

from lua-language-server.

Related Issues (20)

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.