diff options
author | bscan <10503608+bscan@users.noreply.github.com> | 2023-11-01 22:58:51 -0400 |
---|---|---|
committer | bscan <10503608+bscan@users.noreply.github.com> | 2023-11-01 22:58:51 -0400 |
commit | c4ec47a8b259e9d95a0d21cbba25b8b89c895ea1 (patch) | |
tree | 3755a04f3e0bed8eab4a7dd9ef994f3863cbea0e /server | |
parent | c9926c582aff4cb67b856764aa039779146d27d4 (diff) | |
download | PerlNavigator-c4ec47a8b259e9d95a0d21cbba25b8b89c895ea1.zip |
Fixing comment/doc blocks, including for CRLF line endings
Diffstat (limited to 'server')
-rw-r--r-- | server/src/hover.ts | 4 | ||||
-rw-r--r-- | server/src/pod.ts | 14 |
2 files changed, 11 insertions, 7 deletions
diff --git a/server/src/hover.ts b/server/src/hover.ts index 3509342..4fce04d 100644 --- a/server/src/hover.ts +++ b/server/src/hover.ts @@ -33,7 +33,9 @@ export async function getHover(params: TextDocumentPositionParams, perlDoc: Perl let docs = await getPod(elem, perlDoc, modMap); if(docs){ - merged += "\n" + docs; + if(!docs.startsWith("\n")) + docs = "\n" + docs; // Markdown requires two newlines to make one + merged += `\n${docs}`; } const hoverContent: MarkupContent = { diff --git a/server/src/pod.ts b/server/src/pod.ts index 798b70c..3c5d9a3 100644 --- a/server/src/pod.ts +++ b/server/src/pod.ts @@ -33,16 +33,18 @@ export async function getPod(elem: PerlElem, perlDoc: PerlDocument, modMap: Map< return; } + let markdown = ""; + // Quick search for leading comments of a very specific form with comment blocks the preceed a sub (and aren't simply get/set without docs) // These regexes are painful, but I didn't want to mix this with the line-by-line POD parsing which would overcomplicate that piece let match, match2; - if(searchItem && (match = fileContent.match(`\\n#####+\\n# +${searchItem}\\n((?:(?:#.*| *)\\n)+)sub +${searchItem}\\b`))){ - if(!( (match2 = searchItem.match(/^get_(\w+)$/)) && match[1].match(new RegExp(`^(?:# +set_${match2[1]}\\n)?[\\s#]*$`)))) - podContent += match[1].replace(/^\s*#+/gm,''); + if(searchItem && (match = fileContent.match(`\\r?\\n#(?:####+| \-+) *(?:\\r?\\n# *)*${searchItem}\\r?\\n((?:(?:#.*| *)\\r?\\n)+)sub +${searchItem}\\b`))){ + if(!( (match2 = searchItem.match(/^get_(\w+)$/)) && match[1].match(new RegExp(`^(?:# +set_${match2[1]}\\r?\\n)?[\\s#]*$`)))) + markdown += "```text\n" + match[1].replace(/^ *#+ ?/gm,'') + "\n```\n" } // Split the file into lines and iterate through them - const lines = fileContent.split("\n"); + const lines = fileContent.split(/\r?\n/); for (const line of lines) { if (line.startsWith("=cut")) { // =cut lines are not added. @@ -81,9 +83,9 @@ export async function getPod(elem: PerlElem, perlDoc: PerlDocument, modMap: Map< } } - const markDown = convertPODToMarkdown(podContent); + markdown += convertPODToMarkdown(podContent); - return markDown; + return markdown; } |