-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add package json handler * improve url handler * fix linting * extend readme.md
- Loading branch information
Showing
12 changed files
with
162 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
local helper = require("gx.helper") | ||
|
||
local M = {} | ||
|
||
-- only package.json | ||
M.filetype = "json" | ||
M.filename = "package.json" | ||
|
||
-- navigate to neovim github plugin url | ||
function M.handle(mode, line) | ||
local pattern = '["]([^%s]*)["]:' | ||
local npm_package = helper.find(line, mode, pattern) | ||
if not npm_package then | ||
return | ||
end | ||
return "https://www.npmjs.com/package/" .. npm_package | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,97 @@ | ||
local helper = require("gx.helper") | ||
local handler = require("gx.handler") | ||
local stub = require("luassert.stub") | ||
|
||
describe("test handler", function() | ||
local activated_handlers = { | ||
plugin = false, | ||
github = false, | ||
package_json = false, | ||
} | ||
|
||
before_each(function() | ||
before_mock_filetype = vim.bo.filetype | ||
end) | ||
|
||
after_each(function() | ||
vim.bo.filetype = before_mock_filetype | ||
end) | ||
|
||
it("no extra handlers on", function() | ||
local filetype = "lua" | ||
-- mock filetype | ||
vim.bo.filetype = "lua" | ||
|
||
assert.equals("https://github.com", handler.get_url("v", "github.com", activated_handlers)) | ||
assert.equals( | ||
"https://github.com", | ||
handler.get_url("v", "github.com", filetype, activated_handlers) | ||
handler.get_url("v", "https://github.com", activated_handlers) | ||
) | ||
assert.equals( | ||
"https://github.com", | ||
handler.get_url("v", "https://github.com", filetype, activated_handlers) | ||
) | ||
assert.equals( | ||
nil, | ||
handler.get_url("v", '"example_user/example_plugin"', "lua", activated_handlers) | ||
) | ||
assert.equals(nil, handler.get_url("v", "Fixes #22", filetype, activated_handlers)) | ||
assert.equals(nil, handler.get_url("v", '"example_user/example_plugin"', activated_handlers)) | ||
assert.equals(nil, handler.get_url("v", "Fixes #22", activated_handlers)) | ||
end) | ||
|
||
it("plugin handler on", function() | ||
local filetype = "lua" | ||
activated_handlers.plugin = true | ||
|
||
-- mock filetype | ||
vim.bo.filetype = "lua" | ||
|
||
assert.equals("https://github.com", handler.get_url("v", "github.com", activated_handlers)) | ||
assert.equals( | ||
"https://github.com", | ||
handler.get_url("v", "github.com", filetype, activated_handlers) | ||
) | ||
assert.equals( | ||
"https://github.com", | ||
handler.get_url("v", "https://github.com", filetype, activated_handlers) | ||
handler.get_url("v", "https://github.com", activated_handlers) | ||
) | ||
assert.equals( | ||
"https://github.com/example_user/example_plugin", | ||
handler.get_url("v", '"example_user/example_plugin"', filetype, activated_handlers) | ||
handler.get_url("v", '"example_user/example_plugin"', activated_handlers) | ||
) | ||
end) | ||
|
||
it("plugin handler on wrong filetype", function() | ||
local filetype = "java" | ||
activated_handlers.plugin = true | ||
|
||
-- mock filetype | ||
vim.bo.filetype = "java" | ||
|
||
assert.equals("https://github.com", handler.get_url("v", "github.com", activated_handlers)) | ||
assert.equals( | ||
"https://github.com", | ||
handler.get_url("v", "github.com", filetype, activated_handlers) | ||
) | ||
assert.equals( | ||
"https://github.com", | ||
handler.get_url("v", "https://github.com", filetype, activated_handlers) | ||
) | ||
assert.equals( | ||
nil, | ||
handler.get_url("v", '"example_user/example_plugin"', filetype, activated_handlers) | ||
handler.get_url("v", "https://github.com", activated_handlers) | ||
) | ||
assert.equals(nil, handler.get_url("v", '"example_user/example_plugin"', activated_handlers)) | ||
end) | ||
|
||
it("plugin handler on", function() | ||
local filetype = "lua" | ||
activated_handlers.github = true | ||
|
||
-- mock filetype | ||
vim.bo.filetype = "lua" | ||
|
||
assert.equals("https://github.com", handler.get_url("v", "github.com", activated_handlers)) | ||
assert.equals( | ||
"https://github.com", | ||
handler.get_url("v", "github.com", filetype, activated_handlers) | ||
handler.get_url("v", "https://github.com", activated_handlers) | ||
) | ||
assert.equals( | ||
"https://github.com", | ||
handler.get_url("v", "https://github.com", filetype, activated_handlers) | ||
"https://github.com/chrishrb/gx.nvim/issues/22", | ||
handler.get_url("v", "Fixes #22", activated_handlers) | ||
) | ||
end) | ||
|
||
it("package_json handler on", function() | ||
activated_handlers.package_json = true | ||
|
||
-- mock filetype | ||
vim.bo.filetype = "json" | ||
|
||
stub(helper, "get_filename") | ||
helper.get_filename.on_call_with().returns("package.json") | ||
|
||
assert.equals( | ||
"https://github.com/chrishrb/gx.nvim/issues/22", | ||
handler.get_url("v", "Fixes #22", filetype, activated_handlers) | ||
"https://www.npmjs.com/package/@rushstack/eslint-patch", | ||
handler.get_url("v", '"@rushstack/eslint-patch": "^1.2.0",', activated_handlers) | ||
) | ||
|
||
helper.get_filename:revert() | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
local handler = require("gx.handlers.package_json") | ||
|
||
describe("package_json_handler_does_work", function() | ||
it("package_json", function() | ||
assert.equals( | ||
"https://www.npmjs.com/package/@cucumber/cucumber", | ||
handler.handle("v", '"@cucumber/cucumber": "^9.0.1",') | ||
) | ||
assert.equals( | ||
"https://www.npmjs.com/package/@prisma/client", | ||
handler.handle("v", '"@prisma/client": "^4.11.0",') | ||
) | ||
assert.equals( | ||
"https://www.npmjs.com/package/express", | ||
handler.handle("v", '"express": "^4.18.2",') | ||
) | ||
assert.equals( | ||
"https://www.npmjs.com/package/vue-router", | ||
handler.handle("v", '"vue-router": "^4.1.6"') | ||
) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters