Skip to content

[BUG] Function List mislabels Perl methods when defined with Namespace::sub (no package block) #17043

@wm2015email

Description

@wm2015email

Is there an existing issue for this?

  • I have searched the existing issues

Description of the Issue

Function List mislabels Perl methods when defined with Namespace::sub (no package block)

Summary
When a Perl file defines subs using fully-qualified names like MyClass::new (without a package declaration), the Function List panel groups entries under MyClass (good) but each child entry is labeled MyClass instead of the right-hand portion (e.g., new, foo, etc.). This makes the list unusable for navigation because all items look identical.

Steps to Reproduce

  1. Open a new file, set language to Perl.
  2. Paste the following minimal example (note: no package statement on purpose):
    use strict;
    use warnings;
    
    sub MyClass::new        { return bless {}, 'MyClass' }
    sub MyClass::do_thing   { return 42 }
    sub MyClass::debug      { print "ok\n" }
    
    sub Other::run          { return 'running' }
    sub Other::stop         { return 'stopped' }
  3. Open the Function List side panel (the built-in “functions” button).
  4. Observe the groups and child items.

Expected Behavior

  • Function List shows two groups: MyClass and Other.
  • Under MyClass, the children are new, do_thing, debug.
  • Under Other, the children are run, stop.

Actual Behavior

  • Groups appear as MyClass and Other (✅).
  • Every child item is labeled with the left-hand namespace (e.g., MyClass) instead of the sub name (new, do_thing, debug).
    Same for Other — all children display as Other.

Why This Happens (likely)

The Perl parser for Function List appears to treat sub <word> as the function name and doesn’t extract the part after :: when subs are declared in fully-qualified form (and not within a package block). The display name becomes the left side (MyClass) rather than the right side (new).

Environment

  • Notepad++: [fill in exact version, e.g., 8.6.9] (64-bit)
  • OS: Windows [10/11], [build]
  • Function List: built-in
  • Reproducible with a clean profile: [Yes/No]

Workarounds Tried

  • Using package MyClass; sub new { ... } avoids the issue (Function List shows new correctly), but that changes code style/structure and isn’t equivalent to files that intentionally define fully-qualified subs without a package block.
  • Editing functionList.xml helps only if a regex is added that captures the right-hand side after :: as the function name, but this is non-trivial for most users.

Suggested Fix / Parser Hint

If Function List is using regex-based parsing for Perl, consider a rule for standalone, fully-qualified subs:

  • Detect:

    ^\s*(?<!#)\s*sub\s+([A-Za-z_]\w*)(::([A-Za-z_]\w*))\s*(\([^)]*\))?\s*\{
    
  • Display name should be group = capture 1 (namespace), function = capture 3 (the part after ::).

Alternatively, if grouping is already handled elsewhere, ensure the displayed function name uses the portion after the final :: (e.g., via something like \K or a dedicated funcNameExpr that extracts (?:(?<=::)|(?<=\bsub\s+))[A-Za-z_]\w*).

Edge cases to consider

  • Multiple namespaces (e.g., Foo::Bar::baz)
  • Prototypes: sub MyClass::new ($) { ... }
  • Attributes: sub MyClass::new :prototype($) { ... }
  • Sub definitions across multiple lines with comments/whitespace

Additional Notes

This is a common Perl pattern (defining subs fully-qualified without package), especially in small scripts or when monkey-patching. Having Function List show the correct right-hand name would significantly improve navigation.

Thanks for looking into it!

Steps To Reproduce

Function List mislabels Perl methods when defined with Namespace::sub (no package block)

Summary
When a Perl file defines subs using fully-qualified names like MyClass::new (without a package declaration), the Function List panel groups entries under MyClass (good) but each child entry is labeled MyClass instead of the right-hand portion (e.g., new, foo, etc.). This makes the list unusable for navigation because all items look identical.

Steps to Reproduce

  1. Open a new file, set language to Perl.
  2. Paste the following minimal example (note: no package statement on purpose):
    use strict;
    use warnings;
    
    sub MyClass::new        { return bless {}, 'MyClass' }
    sub MyClass::do_thing   { return 42 }
    sub MyClass::debug      { print "ok\n" }
    
    sub Other::run          { return 'running' }
    sub Other::stop         { return 'stopped' }
  3. Open the Function List side panel (the built-in “functions” button).
  4. Observe the groups and child items.

Expected Behavior

  • Function List shows two groups: MyClass and Other.
  • Under MyClass, the children are new, do_thing, debug.
  • Under Other, the children are run, stop.

Actual Behavior

  • Groups appear as MyClass and Other (✅).
  • Every child item is labeled with the left-hand namespace (e.g., MyClass) instead of the sub name (new, do_thing, debug).
    Same for Other — all children display as Other.

Why This Happens (likely)

The Perl parser for Function List appears to treat sub <word> as the function name and doesn’t extract the part after :: when subs are declared in fully-qualified form (and not within a package block). The display name becomes the left side (MyClass) rather than the right side (new).

Environment

  • Notepad++: [fill in exact version, e.g., 8.6.9] (64-bit)
  • OS: Windows [10/11], [build]
  • Function List: built-in
  • Reproducible with a clean profile: [Yes/No]

Workarounds Tried

  • Using package MyClass; sub new { ... } avoids the issue (Function List shows new correctly), but that changes code style/structure and isn’t equivalent to files that intentionally define fully-qualified subs without a package block.
  • Editing functionList.xml helps only if a regex is added that captures the right-hand side after :: as the function name, but this is non-trivial for most users.

Suggested Fix / Parser Hint

If Function List is using regex-based parsing for Perl, consider a rule for standalone, fully-qualified subs:

  • Detect:

    ^\s*(?<!#)\s*sub\s+([A-Za-z_]\w*)(::([A-Za-z_]\w*))\s*(\([^)]*\))?\s*\{
    
  • Display name should be group = capture 1 (namespace), function = capture 3 (the part after ::).

Alternatively, if grouping is already handled elsewhere, ensure the displayed function name uses the portion after the final :: (e.g., via something like \K or a dedicated funcNameExpr that extracts (?:(?<=::)|(?<=\bsub\s+))[A-Za-z_]\w*).

Edge cases to consider

  • Multiple namespaces (e.g., Foo::Bar::baz)
  • Prototypes: sub MyClass::new ($) { ... }
  • Attributes: sub MyClass::new :prototype($) { ... }
  • Sub definitions across multiple lines with comments/whitespace

Additional Notes

This is a common Perl pattern (defining subs fully-qualified without package), especially in small scripts or when monkey-patching. Having Function List show the correct right-hand name would significantly improve navigation.

Thanks for looking into it!

Current Behavior

Function List mislabels Perl methods when defined with Namespace::sub (no package block)

Summary
When a Perl file defines subs using fully-qualified names like MyClass::new (without a package declaration), the Function List panel groups entries under MyClass (good) but each child entry is labeled MyClass instead of the right-hand portion (e.g., new, foo, etc.). This makes the list unusable for navigation because all items look identical.

Steps to Reproduce

  1. Open a new file, set language to Perl.
  2. Paste the following minimal example (note: no package statement on purpose):
    use strict;
    use warnings;
    
    sub MyClass::new        { return bless {}, 'MyClass' }
    sub MyClass::do_thing   { return 42 }
    sub MyClass::debug      { print "ok\n" }
    
    sub Other::run          { return 'running' }
    sub Other::stop         { return 'stopped' }
  3. Open the Function List side panel (the built-in “functions” button).
  4. Observe the groups and child items.

Expected Behavior

  • Function List shows two groups: MyClass and Other.
  • Under MyClass, the children are new, do_thing, debug.
  • Under Other, the children are run, stop.

Actual Behavior

  • Groups appear as MyClass and Other (✅).
  • Every child item is labeled with the left-hand namespace (e.g., MyClass) instead of the sub name (new, do_thing, debug).
    Same for Other — all children display as Other.

Why This Happens (likely)

The Perl parser for Function List appears to treat sub <word> as the function name and doesn’t extract the part after :: when subs are declared in fully-qualified form (and not within a package block). The display name becomes the left side (MyClass) rather than the right side (new).

Environment

  • Notepad++: [fill in exact version, e.g., 8.6.9] (64-bit)
  • OS: Windows [10/11], [build]
  • Function List: built-in
  • Reproducible with a clean profile: [Yes/No]

Workarounds Tried

  • Using package MyClass; sub new { ... } avoids the issue (Function List shows new correctly), but that changes code style/structure and isn’t equivalent to files that intentionally define fully-qualified subs without a package block.
  • Editing functionList.xml helps only if a regex is added that captures the right-hand side after :: as the function name, but this is non-trivial for most users.

Suggested Fix / Parser Hint

If Function List is using regex-based parsing for Perl, consider a rule for standalone, fully-qualified subs:

  • Detect:

    ^\s*(?<!#)\s*sub\s+([A-Za-z_]\w*)(::([A-Za-z_]\w*))\s*(\([^)]*\))?\s*\{
    
  • Display name should be group = capture 1 (namespace), function = capture 3 (the part after ::).

Alternatively, if grouping is already handled elsewhere, ensure the displayed function name uses the portion after the final :: (e.g., via something like \K or a dedicated funcNameExpr that extracts (?:(?<=::)|(?<=\bsub\s+))[A-Za-z_]\w*).

Edge cases to consider

  • Multiple namespaces (e.g., Foo::Bar::baz)
  • Prototypes: sub MyClass::new ($) { ... }
  • Attributes: sub MyClass::new :prototype($) { ... }
  • Sub definitions across multiple lines with comments/whitespace

Additional Notes

This is a common Perl pattern (defining subs fully-qualified without package), especially in small scripts or when monkey-patching. Having Function List show the correct right-hand name would significantly improve navigation.

Thanks for looking into it!

Expected Behavior

Function List mislabels Perl methods when defined with Namespace::sub (no package block)

Summary
When a Perl file defines subs using fully-qualified names like MyClass::new (without a package declaration), the Function List panel groups entries under MyClass (good) but each child entry is labeled MyClass instead of the right-hand portion (e.g., new, foo, etc.). This makes the list unusable for navigation because all items look identical.

Steps to Reproduce

  1. Open a new file, set language to Perl.
  2. Paste the following minimal example (note: no package statement on purpose):
    use strict;
    use warnings;
    
    sub MyClass::new        { return bless {}, 'MyClass' }
    sub MyClass::do_thing   { return 42 }
    sub MyClass::debug      { print "ok\n" }
    
    sub Other::run          { return 'running' }
    sub Other::stop         { return 'stopped' }
  3. Open the Function List side panel (the built-in “functions” button).
  4. Observe the groups and child items.

Expected Behavior

  • Function List shows two groups: MyClass and Other.
  • Under MyClass, the children are new, do_thing, debug.
  • Under Other, the children are run, stop.

Actual Behavior

  • Groups appear as MyClass and Other (✅).
  • Every child item is labeled with the left-hand namespace (e.g., MyClass) instead of the sub name (new, do_thing, debug).
    Same for Other — all children display as Other.

Why This Happens (likely)

The Perl parser for Function List appears to treat sub <word> as the function name and doesn’t extract the part after :: when subs are declared in fully-qualified form (and not within a package block). The display name becomes the left side (MyClass) rather than the right side (new).

Environment

  • Notepad++: [fill in exact version, e.g., 8.6.9] (64-bit)
  • OS: Windows [10/11], [build]
  • Function List: built-in
  • Reproducible with a clean profile: [Yes/No]

Workarounds Tried

  • Using package MyClass; sub new { ... } avoids the issue (Function List shows new correctly), but that changes code style/structure and isn’t equivalent to files that intentionally define fully-qualified subs without a package block.
  • Editing functionList.xml helps only if a regex is added that captures the right-hand side after :: as the function name, but this is non-trivial for most users.

Suggested Fix / Parser Hint

If Function List is using regex-based parsing for Perl, consider a rule for standalone, fully-qualified subs:

  • Detect:

    ^\s*(?<!#)\s*sub\s+([A-Za-z_]\w*)(::([A-Za-z_]\w*))\s*(\([^)]*\))?\s*\{
    
  • Display name should be group = capture 1 (namespace), function = capture 3 (the part after ::).

Alternatively, if grouping is already handled elsewhere, ensure the displayed function name uses the portion after the final :: (e.g., via something like \K or a dedicated funcNameExpr that extracts (?:(?<=::)|(?<=\bsub\s+))[A-Za-z_]\w*).

Edge cases to consider

  • Multiple namespaces (e.g., Foo::Bar::baz)
  • Prototypes: sub MyClass::new ($) { ... }
  • Attributes: sub MyClass::new :prototype($) { ... }
  • Sub definitions across multiple lines with comments/whitespace

Additional Notes

This is a common Perl pattern (defining subs fully-qualified without package), especially in small scripts or when monkey-patching. Having Function List show the correct right-hand name would significantly improve navigation.

Thanks for looking into it!

Debug Information

# Function List mislabels Perl methods when defined with `Namespace::sub` (no `package` block)

**Summary**  
When a Perl file defines subs using fully-qualified names like `MyClass::new` (without a `package` declaration), the **Function List** panel groups entries under `MyClass` (good) but **each child entry is labeled `MyClass`** instead of the right-hand portion (e.g., `new`, `foo`, etc.). This makes the list unusable for navigation because all items look identical.

## Steps to Reproduce

1. Open a new file, set language to **Perl**.
2. Paste the following minimal example (note: no `package` statement on purpose):
   
   use strict;
   use warnings;
   
   sub MyClass::new        { return bless {}, 'MyClass' }
   sub MyClass::do_thing   { return 42 }
   sub MyClass::debug      { print "ok\n" }
   
   sub Other::run          { return 'running' }
   sub Other::stop         { return 'stopped' }
   
3. Open the **Function List** side panel (the built-in “functions” button).
4. Observe the groups and child items.

## Expected Behavior

- Function List shows two groups: `MyClass` and `Other`.
- Under `MyClass`, the children are **`new`**, **`do_thing`**, **`debug`**.  
- Under `Other`, the children are **`run`**, **`stop`**.

## Actual Behavior

- Groups appear as `MyClass` and `Other` (✅).
- **Every child item is labeled with the left-hand namespace (e.g., `MyClass`)** instead of the sub name (`new`, `do_thing`, `debug`).  
  Same for `Other` — all children display as `Other`.

## Why This Happens (likely)

The Perl parser for Function List appears to treat `sub <word>` as the function name and doesn’t extract the part **after** `::` when subs are declared in fully-qualified form (and not within a `package` block). The display name becomes the left side (`MyClass`) rather than the right side (`new`).

## Environment

- Notepad++: [fill in exact version, e.g., 8.6.9] (64-bit)
- OS: Windows [10/11], [build]
- Function List: built-in
- Reproducible with a clean profile: [Yes/No]

## Workarounds Tried

- Using `package MyClass; sub new { ... }` avoids the issue (Function List shows `new` correctly), but that changes code style/structure and isn’t equivalent to files that intentionally define fully-qualified subs without a package block.
- Editing `functionList.xml` helps only if a regex is added that captures the right-hand side after `::` as the function name, but this is non-trivial for most users.

## Suggested Fix / Parser Hint

If Function List is using regex-based parsing for Perl, consider a rule for standalone, fully-qualified subs:

- Detect:  
  
  ^\s*(?<!#)\s*sub\s+([A-Za-z_]\w*)(::([A-Za-z_]\w*))\s*(\([^)]*\))?\s*\{
  

- Display name should be **group = capture 1** (namespace), **function = capture 3** (the part after `::`).

Alternatively, if grouping is already handled elsewhere, ensure the **displayed function name** uses the portion after the final `::` (e.g., via something like `\K` or a dedicated `funcNameExpr` that extracts `(?:(?<=::)|(?<=\bsub\s+))[A-Za-z_]\w*`).

**Edge cases to consider**
- Multiple namespaces (e.g., `Foo::Bar::baz`)
- Prototypes: `sub MyClass::new ($) { ... }`
- Attributes: `sub MyClass::new :prototype($) { ... }`
- Sub definitions across multiple lines with comments/whitespace

## Additional Notes

This is a common Perl pattern (defining subs fully-qualified without `package`), especially in small scripts or when monkey-patching. Having Function List show the correct right-hand name would significantly improve navigation.

Thanks for looking into it!

Anything else?

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions