Dhanus3133 / Leetbuddy.nvim

Solve Leetcode problems within Neovim 🔥
MIT License
139 stars 15 forks source link

Can't List Any Questions with domain cn #4

Closed andyli386 closed 1 year ago

andyli386 commented 1 year ago

Hello, this is my configuration in neovim { "Dhanus3133/LeetBuddy.nvim", dependencies = { "nvim-lua/plenary.nvim", "nvim-telescope/telescope.nvim", }, config = function() require("leetbuddy").setup({ language = "py", domain = "cn" }) end,

keys = {
  { "<leader>lq", "<cmd>LBQuestions<cr>", desc = "List Questions" },
  { "<leader>ll", "<cmd>LBQuestion<cr>", desc = "View Question" },
  { "<leader>lr", "<cmd>LBReset<cr>", desc = "Reset Code" },
  { "<leader>lt", "<cmd>LBTest<cr>", desc = "Run Code" },
  { "<leader>ls", "<cmd>LBSubmit<cr>", desc = "Submit Code" },
},

} just add 'domain="cn"', I can login with my account but cannot find any questions when I use lq command.

Dhanus3133 commented 1 year ago

The implementation till now I made was focused on global but yet I haven't yet completely added the support for "cn". The support for the "cn" domain is on my radar, and I will be looking into it soon to make fully compatible with the Chinese Leetcode platform.

andyli386 commented 1 year ago

Many thanks

Dhanus3133 commented 1 year ago

Hey @andyli386, The plugin now supports the cn version of Leetcode. If you encounter any issues or have suggestions, please let me know. Thanks.

meetorion commented 1 year ago

I can use this plugin when setting up the COM version, but the CN version doesn't work.

mongiaK commented 1 year ago

you can change questions.lua file two points:

one:(modify)

local function filter_problems() -- local cancel = function() end return function(prompt) if config.domain == "cn" then return display_questions_cn(prompt) else return display_questions(prompt) end end end

two:(add function)

local function display_questions_cn(search_query) local graphql_endpoint = config.graphql_endpoint

local variables = {
    categorySlug = "",
    limit = 40,
    skip = 0,
    filters = {
        difficulty = M.difficulty,
        searchKeywords = search_query,
        status = M.status,
    }
}

local query = [[
        query problemsetQuestionList($categorySlug: String, $limit: Int, $skip: Int, $filters: QuestionListFilterInput) {
            problemsetQuestionList(
                categorySlug: $categorySlug
                limit: $limit
                skip: $skip
                filters: $filters) {
                    hasMore
                    total
                    questions {
                        acRate
                        difficulty
                        freqBar
                        frontendQuestionId
                        isFavor
                        paidOnly
                        solutionNum
                        status
                        title
                        titleCn
                        titleSlug
                        topicTags {
                            name
                            nameTranslated
                            id
                            slug
                        }
                        extra {
                            hasVideoSolution
                            topCompanyTags {
                                imgUrl
                                slug
                                numSubscribed
                            }
                        }
                    }
                }
            }
            ]]

local response =
    curl.post(graphql_endpoint,
        {
            headers = headers,
            body = vim.json.encode({ operationName = "problemsetQuestionList", query = query, variables = variables })
        })
--print(response["body"])
local data = vim.json.decode(response["body"])["data"]["problemsetQuestionList"]
return (data ~= vim.NIL and data["questions"] or {})

end