-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from piersolenski/feature/insert_position
Line position
- Loading branch information
Showing
8 changed files
with
135 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
local function get_filetype_config(languages, filetype) | ||
for _, config in ipairs(languages) do | ||
for _, current_filetype in ipairs(config.filetypes) do | ||
if current_filetype == filetype then | ||
return config | ||
end | ||
end | ||
end | ||
return nil | ||
end | ||
|
||
return get_filetype_config |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
local function validate_language(lang) | ||
vim.validate({ | ||
extensions = { lang.extensions, "table" }, | ||
filetypes = { lang.filetypes, "table" }, | ||
regex = { lang.regex, "string" }, | ||
insert_at_line = { lang.insert_at_line, { "nil", "number", "function" }, true }, | ||
}) | ||
|
||
for _, ext in ipairs(lang.extensions) do | ||
vim.validate({ extension = { ext, "string" } }) | ||
end | ||
|
||
for _, ft in ipairs(lang.filetypes) do | ||
vim.validate({ filetype = { ft, "string" } }) | ||
end | ||
end | ||
|
||
local function validate_config(opts) | ||
vim.validate({ | ||
insert_at_top = { opts.insert_at_top, { "boolean" } }, | ||
custom_languages = { | ||
opts.custom_languages, | ||
function(value) | ||
if type(value) ~= "table" and value ~= nil then | ||
return false, "custom_languages must be a table or nil" | ||
end | ||
|
||
if value ~= nil then | ||
for _, lang in ipairs(value) do | ||
if type(lang) ~= "table" then | ||
return false, "each item in custom_languages must be a table" | ||
end | ||
local ok, err = pcall(validate_language, lang) | ||
if not ok then | ||
return false, err | ||
end | ||
end | ||
end | ||
|
||
return true | ||
end, | ||
}, | ||
}) | ||
end | ||
|
||
return validate_config |
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