Skip to content

Commit

Permalink
fix: don't show possibly misleading info or diagnostics for local dep…
Browse files Browse the repository at this point in the history
…encencies

Since we currently can't resolve workspace, path, or git depencencies
there is no guarantee that any crate with the same name we would fetch
from crates.io is in any way related to local dependency.
  • Loading branch information
saecki committed Aug 8, 2023
1 parent 4ce7c51 commit d5333df
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 75 deletions.
14 changes: 10 additions & 4 deletions lua/crates/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,17 @@ function M.update(buf, reload)
ui.clear(buf)
ui.display_diagnostics(buf, diagnostics)
for k, c in pairs(crate_cache) do
local crate = state.api_cache[c:package()]
local versions = crate and crate.versions

if not reload and crate then
local info, c_diagnostics = diagnostic.process_api_crate(c, crate)

if c.dep_kind ~= "registry" then
return
end

local api_crate = state.api_cache[c:package()]
local versions = api_crate and api_crate.versions

if not reload and api_crate then
local info, c_diagnostics = diagnostic.process_api_crate(c, api_crate)
cache.info[k] = info
vim.list_extend(cache.diagnostics, c_diagnostics)

Expand Down
30 changes: 10 additions & 20 deletions lua/crates/diagnostic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -231,29 +231,19 @@ function M.process_api_crate(crate, api_crate)
}
local diagnostics = {}

if crate.workspace then
info.dep_kind = "workspace"
elseif crate.path then
info.dep_kind = "path"
elseif crate.git then
info.dep_kind = "git"
else
info.dep_kind = "registry"
end

if api_crate then
if api_crate.name ~= crate:package() then
table.insert(diagnostics, crate_diagnostic(
crate,
"crate_name_case",
vim.diagnostic.severity.ERROR,
nil,
{ crate = crate, crate_name = api_crate.name }))
if crate.dep_kind == "registry" then
if api_crate then
if api_crate.name ~= crate:package() then
table.insert(diagnostics, crate_diagnostic(
crate,
"crate_name_case",
vim.diagnostic.severity.ERROR,
nil,
{ crate = crate, crate_name = api_crate.name }))

end
end
end

if info.dep_kind == "registry" then
if newest then
if semver.matches_requirements(newest.parsed, crate:vers_reqs()) then

Expand Down
18 changes: 18 additions & 0 deletions lua/crates/toml.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ local M = {Section = {}, Crate = {Vers = {}, Registry = {}, Path = {}, Git = {},














Expand Down Expand Up @@ -197,6 +205,16 @@ function Crate.new(obj)
obj.opt.enabled = obj.opt.text ~= "false"
end

if obj.workspace then
obj.dep_kind = "workspace"
elseif obj.path then
obj.dep_kind = "path"
elseif obj.git then
obj.dep_kind = "git"
else
obj.dep_kind = "registry"
end

return setmetatable(obj, { __index = Crate })
end

Expand Down
8 changes: 0 additions & 8 deletions lua/crates/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,6 @@ local M = {CrateInfo = {}, Diagnostic = {}, Crate = {}, Version = {}, Features =














Expand Down
6 changes: 1 addition & 5 deletions lua/crates/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ function M.display_crate_info(buf, info, diagnostics)
})
end

if info.dep_kind == "path" then

elseif info.dep_kind == "git" then

elseif info.dep_kind == "registry" and not (info.vers_match or info.vers_upgrade) then
if not (info.vers_match or info.vers_upgrade) then
table.insert(virt_text, {
state.cfg.text.error,
state.cfg.highlight.error,
Expand Down
14 changes: 10 additions & 4 deletions teal/crates/core.tl
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,17 @@ function M.update(buf: integer|nil, reload: boolean)
ui.clear(buf)
ui.display_diagnostics(buf, diagnostics)
for k,c in pairs(crate_cache) do
local crate = state.api_cache[c:package()]
local versions = crate and crate.versions
-- Don't try to fetch info from crates.io if it's a local or git crate
-- TODO: Once there is workspace support, resolve the crate
if c.dep_kind ~= "registry" then
return
end

local api_crate = state.api_cache[c:package()]
local versions = api_crate and api_crate.versions

if not reload and crate then
local info, c_diagnostics = diagnostic.process_api_crate(c, crate)
if not reload and api_crate then
local info, c_diagnostics = diagnostic.process_api_crate(c, api_crate)
cache.info[k] = info
vim.list_extend(cache.diagnostics, c_diagnostics)

Expand Down
32 changes: 11 additions & 21 deletions teal/crates/diagnostic.tl
Original file line number Diff line number Diff line change
Expand Up @@ -231,29 +231,19 @@ function M.process_api_crate(crate: toml.Crate, api_crate: Crate): CrateInfo, {D
}
local diagnostics = {}

if crate.workspace then
info.dep_kind = "workspace"
elseif crate.path then
info.dep_kind = "path"
elseif crate.git then
info.dep_kind = "git"
else
info.dep_kind = "registry"
end

if api_crate then
if api_crate.name ~= crate:package() then
table.insert(diagnostics, crate_diagnostic(
crate,
"crate_name_case",
vim.diagnostic.severity.ERROR,
nil,
{ crate = crate, crate_name = api_crate.name }
))
if crate.dep_kind == "registry" then
if api_crate then
if api_crate.name ~= crate:package() then
table.insert(diagnostics, crate_diagnostic(
crate,
"crate_name_case",
vim.diagnostic.severity.ERROR,
nil,
{ crate = crate, crate_name = api_crate.name }
))
end
end
end

if info.dep_kind == "registry" then
if newest then
if semver.matches_requirements(newest.parsed, crate:vers_reqs()) then
-- version matches, no upgrade available
Expand Down
18 changes: 18 additions & 0 deletions teal/crates/toml.tl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ local record M
def: Def
feat: Feat
section: Section
dep_kind: DepKind

enum Syntax
"plain"
Expand Down Expand Up @@ -135,6 +136,13 @@ local record M
end
end

enum DepKind
"registry"
"path"
"git"
"workspace"
end

record Feature
name: string
col: Range -- relative to to the start of the features text
Expand Down Expand Up @@ -197,6 +205,16 @@ function Crate.new(obj: Crate): Crate
obj.opt.enabled = obj.opt.text ~= "false"
end

if obj.workspace then
obj.dep_kind = "workspace"
elseif obj.path then
obj.dep_kind = "path"
elseif obj.git then
obj.dep_kind = "git"
else
obj.dep_kind = "registry"
end

return setmetatable(obj, { __index = Crate })
end

Expand Down
8 changes: 0 additions & 8 deletions teal/crates/types.tl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ local record M
vers_update: Version
vers_upgrade: Version
match_kind: MatchKind
dep_kind: DepKind
end

enum MatchKind
Expand All @@ -16,13 +15,6 @@ local record M
"nomatch"
end

enum DepKind
"registry"
"path"
"git"
"workspace"
end

record Diagnostic
lnum: integer
end_lnum: integer
Expand Down
6 changes: 1 addition & 5 deletions teal/crates/ui.tl
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ function M.display_crate_info(buf: integer, info: CrateInfo, diagnostics: {Diagn
})
end

if info.dep_kind == "path" then
-- TODO: display relevant information
elseif info.dep_kind == "git" then
-- TODO: display relevant information
elseif info.dep_kind == "registry" and not (info.vers_match or info.vers_upgrade) then
if not (info.vers_match or info.vers_upgrade) then
table.insert(virt_text, {
state.cfg.text.error,
state.cfg.highlight.error,
Expand Down

0 comments on commit d5333df

Please sign in to comment.