smjonas / inc-rename.nvim

Incremental LSP renaming based on Neovim's command-preview feature.
MIT License
668 stars 9 forks source link

In a typescript file, I get an error, Request textDocument/references failed: "Cannot read properties of undefined" #1

Closed NullVoxPopuli closed 2 years ago

NullVoxPopuli commented 2 years ago

Specifically on this branch: https://github.com/NullVoxPopuli/ember-resources/pull/513 in ember-resources/src/core/resource.ts around line 180, I tried renaming cache.

And got this error:

2022-06-03T20:22:33 ERROR Error while finding references: Request textDocument/references failed with message: Cannot read propert
ies of undefined (reading 'includeDeclaration')
2022-06-03T20:22:38 WARN No results from textDocument/references
2022-06-03T20:22:38 ERROR Error while finding references: Request textDocument/references failed with message: Cannot read propert
ies of undefined (reading 'includeDeclaration')
2022-06-03T20:22:38 WARN No results from textDocument/references
2022-06-03T20:22:38 ERROR Error while finding references: Request textDocument/references failed with message: Cannot read propert
ies of undefined (reading 'includeDeclaration')
2022-06-03T20:22:38 WARN No results from textDocument/references
2022-06-03T20:22:38 ERROR Error while finding references: Request textDocument/references failed with message: Cannot read propert
ies of undefined (reading 'includeDeclaration')
2022-06-03T20:22:38 WARN No results from textDocument/references
2022-06-03T20:22:38 ERROR Error while finding references: Request textDocument/references failed with message: Cannot read propert
ies of undefined (reading 'includeDeclaration')
2022-06-03T20:22:39 WARN No results from textDocument/references
2022-06-03T20:22:39 ERROR Error while finding references: Request textDocument/references failed with message: Cannot read propert
ies of undefined (reading 'includeDeclaration')

(history from nvim-notify)

which I think is from: https://github.com/smjonas/inc-rename.nvim/blob/main/lua/inc_rename/init.lua#L23

the code that triggered the error:

class ResourceManager {
  capabilities = helperCapabilities('3.23', {
    hasValue: true,
    hasDestroyable: true,
  });

  constructor(protected owner: unknown) {}

  createHelper(Class: typeof Resource, args: ArgsWrapper) {
    let owner = this.owner;

    let instance: Resource<ArgsWrapper>;

    // right here, I tried rename on `cache`
    let cache: Cache = createCache(() => {
      if (instance === undefined) {
        instance = new Class(owner);

        associateDestroyableChild(cache, instance);
      }

      if (instance.modify) {
        instance.modify(args.positional, args.named);
      }

      return instance;
    });

    return cache;
  }

in lua files, works as expected

NullVoxPopuli commented 2 years ago

fixed! thanks!