Skip to content

Commit

Permalink
feat(go): add initial go chase
Browse files Browse the repository at this point in the history
Check if root directory is a go project.

Refs: #16
  • Loading branch information
piraz committed Jun 27, 2024
1 parent 146e4d1 commit f5077c4
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
52 changes: 52 additions & 0 deletions lua/chase/go.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
local chase = require("chase")
local Log = chase.log
local Path = require("plenary.path")

local M = {}

M.buf_name_prefix = "ChaseGo: "

M.setup_called = false
M.vim_did_enter = false

M.go_bin = nil
M.go_arch = nil
M.go_version = nil

function M.is_go_project()
if chase.project_root:joinpath("go.mod"):exists() then
return true
end
return false
end

function M.setup_project_go()

if M.setup_called then
if M.is_go_project() then
-- local cwd_x = vim.fn.split(vim.fn.getcwd(), chase.sep)
vim.fn.jobstart(
{ "which", "go" },
{
stdout_buffered = true,
on_stdout = function(_, which_data)
M.go_bin = vim.fn.join(which_data, "")
vim.fn.jobstart(
{ M.go_bin, "version" },
{
stdout_buffered = true,
on_stdout = function(_, version_data)
local go_version = vim.fn.split(
vim.fn.join(version_data, ""), "")
M.go_arch = go_version[4]
M.go_version = go_version[3]
end,
})
end,
})
end
end
end
-- M.setup_called = true
-- M.setup_project_go()
return M
3 changes: 3 additions & 0 deletions tests/fixtures/go/go_project/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module candango.org/go_project

go 1.22.4
16 changes: 16 additions & 0 deletions tests/go_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
local chase = require("chase")
local go = require("chase.go")
local test = require("chase.test")

describe("Chase Go", function()
local path = vim.fn.getcwd()
it(path .. " isn't a go project", function()
assert.are.False(go.is_go_project())
end)
path = vim.fn.join(
{ vim.fn.getcwd(), "tests", "fixtures", "go", "go_project"}, chase.sep)
it(path .. " is a go project", function()
test.setup_project(path)
assert.are.True(go.is_go_project())
end)
end)

0 comments on commit f5077c4

Please sign in to comment.