From b8e7a77ea53831c11c294287f0cd9c91d1c05263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Reegn?= Date: Thu, 8 May 2025 13:12:32 +0200 Subject: [PATCH 1/4] feat(python): add handler for python PEPs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit python peps are enhancement proposal documents, they are usually referred to as PEP-xxx, PEP xxx or PEPxxx, the handler handles each of those cases. Signed-off-by: Zoltán Reegn --- lua/gx/handlers/python-pep.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 lua/gx/handlers/python-pep.lua diff --git a/lua/gx/handlers/python-pep.lua b/lua/gx/handlers/python-pep.lua new file mode 100644 index 0000000..005dd65 --- /dev/null +++ b/lua/gx/handlers/python-pep.lua @@ -0,0 +1,18 @@ +local helper = require("gx.helper") + +---@type GxHandler +local M = { + name = "python-pep", + filetype = nil, + filename = nil, +} + +function M.handle(mode, line, _) + local id = helper.find(line, mode, "PEP%s?-?(%d+)") + if not id then + return + end + return "https://peps.python.org/" .. "pep-" .. id +end + +return M From f21cdf282fb3505ecc5f767e6de3b804e5f4198a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Reegn?= Date: Mon, 7 Jul 2025 15:14:14 +0200 Subject: [PATCH 2/4] add test case --- test/spec/gx/handlers/python-pep_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 test/spec/gx/handlers/python-pep_spec.lua diff --git a/test/spec/gx/handlers/python-pep_spec.lua b/test/spec/gx/handlers/python-pep_spec.lua new file mode 100644 index 0000000..bed1e50 --- /dev/null +++ b/test/spec/gx/handlers/python-pep_spec.lua @@ -0,0 +1,7 @@ +local handler = require("gx.handlers.python-pep") + +describe("python-pep_handler_does_work", function() + it("python-pep", function() + assert.equals("https://peps.python.org/pep-484", handler.handle("v", "# PEP-484")) + end) +end) From 4d74847bd587b0b826d3296cb9de9125d1969fcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Reegn?= Date: Mon, 7 Jul 2025 17:14:21 +0200 Subject: [PATCH 3/4] add additional test cases --- test/spec/gx/handlers/python-pep_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/spec/gx/handlers/python-pep_spec.lua b/test/spec/gx/handlers/python-pep_spec.lua index bed1e50..5861710 100644 --- a/test/spec/gx/handlers/python-pep_spec.lua +++ b/test/spec/gx/handlers/python-pep_spec.lua @@ -4,4 +4,10 @@ describe("python-pep_handler_does_work", function() it("python-pep", function() assert.equals("https://peps.python.org/pep-484", handler.handle("v", "# PEP-484")) end) + it("python-pep", function() + assert.equals("https://peps.python.org/pep-484", handler.handle("v", "# PEP484")) + end) + it("python-pep", function() + assert.equals("https://peps.python.org/pep-484", handler.handle("v", "# PEP 484")) + end) end) From cc1cfb7049f267d39a0c476adbdc776554a702cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Reegn?= Date: Tue, 8 Jul 2025 10:39:35 +0200 Subject: [PATCH 4/4] register handler --- lua/gx/handler.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/gx/handler.lua b/lua/gx/handler.lua index 25f1311..8880cc7 100644 --- a/lua/gx/handler.lua +++ b/lua/gx/handler.lua @@ -8,6 +8,7 @@ local go_handler = require("gx.handlers.go") local commit_handler = require("gx.handlers.commit") local markdown_handler = require("gx.handlers.markdown") local cve_handler = require("gx.handlers.cve") +local python_pep_handler = require("gx.handlers.python-pep") local search_handler = require("gx.handlers.search") local M = {} @@ -48,6 +49,7 @@ local function resolve_handlers(handlers) add_handler(resolved, go_handler, handlers.go and exists.go == nil) add_handler(resolved, markdown_handler, handlers.markdown and exists.markdown == nil) add_handler(resolved, cve_handler, handlers.cve and exists.cve == nil) + add_handler(resolved, python_pep_handler, handlers.python_pep and exists.python_pep == nil) add_handler(resolved, url_handler, handlers.url and exists.url == nil) add_handler(resolved, search_handler, handlers.search and exists.search == nil) -- ###