diff --git a/teal/crates/diagnostic.tl b/teal/crates/diagnostic.tl index 1830eeee..d474abec 100644 --- a/teal/crates/diagnostic.tl +++ b/teal/crates/diagnostic.tl @@ -231,7 +231,9 @@ function M.process_api_crate(crate: toml.Crate, api_crate: Crate): CrateInfo, {D } local diagnostics = {} - if crate.path then + if crate.workspace then + info.dep_kind = "workspace" + elseif crate.path then info.dep_kind = "path" elseif crate.git then info.dep_kind = "git" diff --git a/teal/crates/toml.tl b/teal/crates/toml.tl index fe922af0..d12fcc94 100644 --- a/teal/crates/toml.tl +++ b/teal/crates/toml.tl @@ -28,6 +28,7 @@ local record M path: Path git: Git pkg: Pkg + workspace: Workspace def: Def feat: Feat section: Section @@ -72,6 +73,14 @@ local record M quote: Quotes end + record Workspace + enabled: boolean + text: string + line: integer -- 0-indexed + col: Range + decl_col: Range + end + record Def enabled: boolean text: string @@ -129,6 +138,7 @@ local INLINE_TABLE_GIT_PATTERN = inline_table_str_pattern("git") local INLINE_TABLE_PKG_PATTERN = inline_table_str_pattern("package") local INLINE_TABLE_FEAT_PATTERN = inline_table_str_array_pattern("features") local INLINE_TABLE_DEF_PATTERN = inline_table_bool_pattern("default[_-]features") +local INLINE_TABLE_WORKSPACE_PATTERN = inline_table_bool_pattern("workspace") function M.parse_crate_features(text: string): {Feature} local feats: {Feature} = {} @@ -163,6 +173,9 @@ function Crate.new(obj: Crate): Crate if obj.def then obj.def.enabled = obj.def.text ~= "false" end + if obj.workspace then + obj.workspace.enabled = obj.workspace.text ~= "false" + end return setmetatable(obj, { __index = Crate }) end @@ -197,6 +210,10 @@ function Crate:is_def_enabled(): boolean return not self.def or self.def.enabled end +function Crate:is_workspace(): boolean + return not self.workspace or self.workspace.enabled +end + function Crate:package(): string return self.pkg and self.pkg.text or self.explicit_name end @@ -320,8 +337,8 @@ function M.parse_crate_table_feat(line: string, line_nr: integer): Crate.Feat return nil end -function M.parse_crate_table_def(line: string, line_nr: integer): Crate.Def - local bool_s, text, bool_e = line:match("^%s*default[_-]features%s*=%s*()([^%s]*)()%s*$") +local function parse_crate_table_bool(line: string, line_nr: integer, pattern: string): table|nil + local bool_s, text, bool_e = line:match(pattern) if text then return { text = text, @@ -334,6 +351,16 @@ function M.parse_crate_table_def(line: string, line_nr: integer): Crate.Def return nil end +function M.parse_crate_table_def(line: string, line_nr: integer): Crate.Def + local pat = "^%s*default[_-]features%s*=%s*()([^%s]*)()%s*$" + return parse_crate_table_bool(line, line_nr, pat) as Crate.Def +end + +function M.parse_crate_table_workspace(line: string, line_nr: integer): Crate.Def + local pat = "^%s*workspace%s*=%s*()([^%s]*)()%s*$" + return parse_crate_table_bool(line, line_nr, pat) as Crate.Def +end + local function parse_inline_table_str(crate: Crate, line: string, line_nr: integer, entry: string, pattern: string) local name_s, name, name_e, decl_s, quote_s, str_s, text, str_e, quote_e, decl_e = line:match(pattern) if name then @@ -351,6 +378,22 @@ local function parse_inline_table_str(crate: Crate, line: string, line_nr: integ end end +local function parse_inline_table_bool(crate: Crate, line: string, line_nr: integer, entry: string, pattern: string) + local name_s, name, name_e, decl_s, quote_s, str_s, text, str_e, quote_e, decl_e = line:match(pattern) + if name then + crate.explicit_name = name + crate.explicit_name_col = Range.new(name_s as integer - 1, name_e as integer - 1) + do + (crate as {string:any})[entry] = { + text = text, + line = line_nr, + col = Range.new(str_s as integer - 1, str_e as integer - 1), + decl_col = Range.new(decl_s as integer - 1, decl_e as integer - 1), + } + end + end +end + function M.parse_crate(line: string, line_nr: integer): Crate -- plain version do diff --git a/teal/crates/types.tl b/teal/crates/types.tl index 04f259fb..cb9c0bc4 100644 --- a/teal/crates/types.tl +++ b/teal/crates/types.tl @@ -20,6 +20,7 @@ local record M "registry" "path" "git" + "workspace" end record Diagnostic