diff options
author | bscan <10503608+bscan@users.noreply.github.com> | 2023-10-31 22:36:20 -0400 |
---|---|---|
committer | bscan <10503608+bscan@users.noreply.github.com> | 2023-10-31 22:36:20 -0400 |
commit | bde181abd3feb0f3cd213c8bc974b47be61e7f1c (patch) | |
tree | da75af56b5e90f5c1778ab0556fc2f52621d6678 | |
parent | 340f4445fbba56eb88bace28dde71605ed5eaaff (diff) | |
download | PerlNavigator-bde181abd3feb0f3cd213c8bc974b47be61e7f1c.zip |
Adding comment style documentation parsing
-rw-r--r-- | server/src/pod.ts | 13 | ||||
-rw-r--r-- | testWorkspace/MyLib/NamedPackage.pm | 15 | ||||
-rw-r--r-- | testWorkspace/mainTest.pl | 4 |
3 files changed, 25 insertions, 7 deletions
diff --git a/server/src/pod.ts b/server/src/pod.ts index f8d2497..798b70c 100644 --- a/server/src/pod.ts +++ b/server/src/pod.ts @@ -25,13 +25,22 @@ export async function getPod(elem: PerlElem, perlDoc: PerlDocument, modMap: Map< let searchItem; if([PerlSymbolKind.Package, PerlSymbolKind.Module].includes(elem.type)){ // Search all. Note I'm not really treating packages different from Modules - } else if([PerlSymbolKind.ImportedSub, PerlSymbolKind.Method, PerlSymbolKind.Inherited, PerlSymbolKind.PathedField].includes(elem.type)){ + } else if([PerlSymbolKind.ImportedSub, PerlSymbolKind.Method, PerlSymbolKind.Inherited, PerlSymbolKind.PathedField, + PerlSymbolKind.LocalMethod, PerlSymbolKind.LocalSub].includes(elem.type)){ searchItem = elem.name; searchItem = searchItem.replace(/^[\w:]+::(\w+)$/, "$1"); // Remove package } else { return; } + // 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,''); + } + // Split the file into lines and iterate through them const lines = fileContent.split("\n"); for (const line of lines) { @@ -43,7 +52,7 @@ export async function getPod(elem: PerlElem, perlDoc: PerlDocument, modMap: Map< if (line.match(/^=(pod|head\d|over|item|back|begin|end|for|encoding)/)) { inPodBlock = true; meaningFullContent = false; - if(line.match(new RegExp(`^=(head\\d|item).*\\b${searchItem}\\b`))){ + if(searchItem && line.match(new RegExp(`^=(head\\d|item).*\\b${searchItem}\\b`))){ // This is structured so if we hit two relevant block in a row, we keep them both inRelevantBlock = true; } else { diff --git a/testWorkspace/MyLib/NamedPackage.pm b/testWorkspace/MyLib/NamedPackage.pm index 4dc7435..0845ab6 100644 --- a/testWorkspace/MyLib/NamedPackage.pm +++ b/testWorkspace/MyLib/NamedPackage.pm @@ -5,7 +5,7 @@ use warnings; require Exporter; our @ISA = qw(Exporter); -our @EXPORT_OK = qw(exported_sub imported_constant $our_variable); +our @EXPORT_OK = qw(get_value imported_constant $our_variable); use constant imported_constant => "I'm an imported constant"; @@ -15,10 +15,19 @@ sub can { exists $_[0]->{$_[1]}; } -sub exported_sub { - print "In Dir::NamedPackage, sub exported_sub\n"; +###### +# get_value +# set_value + +sub get_value { + print "In Dir::NamedPackage, sub get_value\n"; } +######## +# non_exported_sub +# Documentation +# Example + sub non_exported_sub { print "In Dir::NamedPackage, sub non_exported_sub\n"; } diff --git a/testWorkspace/mainTest.pl b/testWorkspace/mainTest.pl index 39f0b31..8d33e41 100644 --- a/testWorkspace/mainTest.pl +++ b/testWorkspace/mainTest.pl @@ -11,7 +11,7 @@ use Cwd qw(fast_abs_path); # fast_abs_path is pure perl. use MIME::Base64 qw(encode_base64); # encode_base64 is XS, so the best we can do is find the .pm use File::Copy; # Workspace modules -use MyLib::NamedPackage qw(exported_sub imported_constant $our_variable); +use MyLib::NamedPackage qw(get_value imported_constant $our_variable); use MyLib::MyClass; use MyLib::MyOtherClass; use MyLib::NonPackage; @@ -94,7 +94,7 @@ SameFilePackage::same_file_package_sub(); sub_with_sig(2,3,4); duplicate_sub_name(); nonpackage_sub(); -exported_sub(); +get_value(); MyLib::NamedPackage::non_exported_sub(); MyLib::NamedPackage::duplicate_sub_name(); MyLib::SubPackage::subpackage_mod(); |