Typescript: New refactor API

Created on 6 Jun 2017  路  3Comments  路  Source: microsoft/TypeScript

Field names may not be correct, this is just conceptual

--> to server
{
  command: "getApplicableRefactors"
  position: 123
  end: 221
}

<-- to client
[
  {
    name: "Extract_Method", // Programmatic
    description: "Extract...", // User display,
    inlineable: true, // True if this can be flattened, false if it should always be nested
                      // Default: True
    actions: [
        {
            name: "Extract_Closure",
            description: "Extract local function",
        },
        {
            name: "Extract_Method_1",
            description: "Extract to method in class 'MyClass'"         
        }
  },
  {
    name: "Delete_It",
    description: "Delete this class",
    actions: [ { name: "Delete_foo" description: "Delete function 'foo'" }]
  }
]

--> to server
{
  command: "getEditsForRefactor"
  position: 123
  end: 321,
  refactor: "Extract_Method", // 'name' from response element
  action: "Extract_Method_1", // 'name' from action element
}

<-- to client
(a set of formatting-style edits) &
 { renameLocation: 123 } // where to start the user renaming a generated identifier (optional)

Reserved fields on all objects: "input" (TBD)

API

Most helpful comment

馃憤

All 3 comments

馃憤

Is it possible to deal with the shorthand key name problem with this new refactoring API? For both destructuring and shorthand object notation, renaming a local can have global effects, and vice-versa; but both could be avoided by converting shorthand to explicit.

@Kovensky eventually, yes. Currently we're not supporting refactors that require inputs, but scenarios like that are definitely on our timeline.

Was this page helpful?
0 / 5 - 0 ratings