From eb01aca460d3a657c8fda36e64d101d85dbd9f78 Mon Sep 17 00:00:00 2001 From: Ashkan Kiani Date: Tue, 26 Nov 2019 06:01:11 -0800 Subject: Add sumneko_lua installation and util.sh helper. (#49) * Add sumneko_lua installation and util.sh helper. * Add vspackage extraction for package.json information via vscode name. * Allow specifying a tempdir at DOCGEN_TEMPDIR * Fix on_new_config and add docs for root_dir * User settings titles are not always useful --- scripts/docgen.lua | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) (limited to 'scripts/docgen.lua') diff --git a/scripts/docgen.lua b/scripts/docgen.lua index 4239ff47..cf474075 100644 --- a/scripts/docgen.lua +++ b/scripts/docgen.lua @@ -115,10 +115,7 @@ local function make_lsp_sections() }) if docs then - local tempdir = os.getenv("PACKAGE_JSON_CACHEDIR") or uv.fs_mkdtemp("/tmp/nvim-lsp.XXXXXX") - if not util.path.is_dir(tempdir) then - fn.mkdir(tempdir) - end + local tempdir = os.getenv("DOCGEN_TEMPDIR") or uv.fs_mkdtemp("/tmp/nvim-lsp.XXXXXX") local preamble_parts = make_parts { function() if docs.description and #docs.description > 0 then @@ -131,19 +128,39 @@ local function make_lsp_sections() end end; function() + local package_json_name = util.path.join(tempdir, template_name..'.package.json'); + if docs.vscode then + docs.vspackage = util.format_vspackage_url(docs.vscode) + end + if docs.vspackage then + local script = [[ + curl -L -o {{vspackage_name}} {{vspackage_url}} + gzip -d {{vspackage_name}} + unzip -j {{vspackage_zip}} extension/package.json + mv package.json {{package_json_name}} + ]] + os.execute(template(script, { + package_json_name = package_json_name; + vspackage_name = util.path.join(tempdir, template_name..'.vspackage.zip.gz'); + vspackage_zip = util.path.join(tempdir, template_name..'.vspackage.zip'); + vspackage_url = docs.vspackage; + })) + if not util.path.is_file(package_json_name) then + print(string.format("Failed to download vspackage for %q at %q", template_name, docs.vspackage)) + return + end + docs.package_json = true + end if docs.package_json then - local filename = util.path.join(tempdir, template_name..'.package.json') - if util.path.is_file(filename) then - os.execute(string.format("curl -L -o %q -z %q %q", filename, filename, docs.package_json)) - else - os.execute(string.format("curl -L -o %q %q", filename, docs.package_json)) + if not util.path.is_file(package_json_name) then + os.execute(string.format("curl -L -o %q %q", package_json_name, docs.package_json)) end - if not util.path.is_file(filename) then - print("Failed to download package.json for %q at %q", template_name, docs.package_json) + if not util.path.is_file(package_json_name) then + print(string.format("Failed to download package.json for %q at %q", template_name, docs.package_json)) os.exit(1) return end - local data = fn.json_decode(readfile(filename)) + local data = fn.json_decode(readfile(package_json_name)) -- The entire autogenerated section. return make_section(0, '\n', { -- The default settings section @@ -153,7 +170,7 @@ local function make_lsp_sections() -- The outer section. return make_section(0, '\n', { 'This server accepts configuration via the `settings` key.'; - '
'..(default_settings.title or "Available settings:")..''; + '
Available settings:'; ''; -- The list of properties. make_section(0, '\n\n', sorted_map_table(default_settings.properties, function(k, v) @@ -189,6 +206,9 @@ local function make_lsp_sections() end end } + if not os.getenv("DOCGEN_TEMPDIR") then + os.execute("rm -rf "..tempdir) + end -- Insert a newline after the preamble if it exists. if #preamble_parts > 0 then table.insert(preamble_parts, '') end params.preamble = table.concat(preamble_parts, '\n') -- cgit v1.2.3-70-g09d2