Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename doesn't keep attribute name in object #85

Closed
gavrilyak opened this issue Oct 30, 2019 · 4 comments · Fixed by #86
Closed

Rename doesn't keep attribute name in object #85

gavrilyak opened this issue Oct 30, 2019 · 4 comments · Fixed by #86

Comments

@gavrilyak
Copy link
Contributor

function f(a, b) {
  return { a, b };
}

When renaming a to c in vim the result is:

function f(c, b) {
  return { c, b };
}

The same renaming in VSCode behaves correctly, the result is:

function f(c, b) {
  return { a: c, b };
}
@chemzqm
Copy link
Member

chemzqm commented Oct 30, 2019

Need tsserver log.

@gavrilyak
Copy link
Contributor Author

tsserver.log

Probably this is just new feature in VSCode.
Proper rename was introduced as new feature in 1.30, and later Microsoft added an option to revert to old behavior. More info here

@gavrilyak
Copy link
Contributor Author

I added providePrefixAndSuffixTextForRename: true in configure request and server response changed.
It now has "prefixText": "a: " but looks like vim ignores it.

Configure

    "preferences": {
        "disableSuggestions": false,
        "importModuleSpecifierPreference": "non-relative",
        "quotePreference": "single",
        "allowRenameOfImportPath": true,
        "providePrefixAndSuffixTextForRename": true,
        "allowTextChangesInNewFiles": true
    }
}

Response from rename is

Result: {
    "info": {
        "canRename": true,
        "displayName": "a",
        "fullDisplayName": "a",
        "kind": "parameter",
        "kindModifiers": "",
        "triggerSpan": {
            "start": {
                "line": 1,
                "offset": 12
            },
            "end": {
                "line": 1,
                "offset": 13
            }
        }
    },
    "locs": [
        {
            "file": "/home/gvv/code/play/rename/rename.js",
            "locs": [
                {
                    "start": {
                        "line": 1,
                        "offset": 12
                    },
                    "end": {
                        "line": 1,
                        "offset": 13
                    }
                },
                {
                    "start": {
                        "line": 2,
                        "offset": 12
                    },
                    "end": {
                        "line": 2,
                        "offset": 13
                    },
                    "prefixText": "a: "
                }
            ]
        }
    ]
}

@gavrilyak
Copy link
Contributor Author

gavrilyak commented Oct 30, 2019

And the fix is

                  changes[uri].push({
                    range: typeConverters.Range.fromTextSpan(textSpan),
-                    newText:  newName
-                    newText:  (textSpan.prefixText || '') + newName + (textSpan.suffixText || '')
                  });

Sorry for not providing proper pull request, npm install is failing on typescript compilation on my computer, just hacking coc-tsserver/lib/index.js.

VSCode reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants