Namespaces and "go to definition"

Open
#82 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript
Domain
tooling

Research direction

Start by reproducing the Go to Definition failure with the namespace layout and imported nsfunc shown in the issue, then trace the LSP's definition lookup for imported names. Done means Go to Definition opens +mynamesp/nsfunc.m and also handles the related class-method and stub-function cases without regressing direct namespace calls.

Written by the indexing model from the issue text.

Description

bug

Describe the bug
The Go to Definition functionality doesn't seem to work when using functions inside a namespace.

To Reproduce

  • In the working folder, create a namespace folder and a function inside it
projectFolder
├── mainfunc.m
├── +mynamep
    ├── nsfunc.m
  • Import and use nsfunc in mainfunc
function out = mainfunc()
    import mynamesp.nsfunc

    out = nsfunc(in);
end
  • Move the cursor on nsfunc (either on the import or on the function call) and call the Go to Definition LSP function.
  • The LSP returns a No LSP defintion found warning.

Expected behavior
Upon calling Go to Definition, LSP should open the file +mynamesp/nsfunc.m.

Note that Go to Definition works correctly if I call the function directly without importing it first, as in

out = mynamesp.nsfunc(in);

Useful Information

  • MATLAB Language Server Version: 1.3.9 (commit 19438c8)
  • MATLAB Version: R2025b
  • OS Version: Linux
  • Language Server Client: Neovim 0.11.6

Additional context

  • The Function Signature Help LSP functionality seems to work well in both cases, suggesting that nsfunc is indexed.
  • While writing the out = mynamesp.nsfunc(in); line, the code completion suggests mynamesp is a function, not a namespace.
  • A similar faulty behavior also appears with other functions defined outside of the current file, for instance with class methods (when using the @class-folder class definition) or when creating stub functions that override built-in ones (e.g., when working with matlab.unittest.fixtures.PathFixture).
Dominant language
TypeScript
Stars
125
Forks
21
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mathworks/MATLAB-language-server

All issues in mathworks/MATLAB-language-server

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.