microsoft / vscode-powerquery

Visual Studio Code extension for Power Query / M.
MIT License
88 stars 16 forks source link

[Enhancement] Allow for multiple `let` `in` statements #204

Open FireFighter1017 opened 1 year ago

FireFighter1017 commented 1 year ago

Is your feature request related to a problem? Please describe. When using copy/paste of queries from a Dataflow editor or Power Query editor (select all queries, then ctrl-c, then go in vscode and paste the code) it always report problems for queries referring to other queries in the same clipboard content. I use this for making mass changes to queries of a same model/dataflow and/or search through code for a particular token.

Describe the solution you'd like It would be nice if we could copy/paste queries and that either it formats the code so that VSCode can recognize query names and stop reporting problems in referencing queries .

Describe alternatives you've considered I have tried using the command powerquery.extractDataflowDocument for Dataflows, but requires that I export the dataflow into a JSON file first and most of the time I'd like to be able to copy/paste, back and forth, while editing the Dataflow. And this method does not apply to pbix Datasets. All that being said, if Power Query editors would let us do find and replace through code, I wouldn't need VS Code at all.

Additional context Here is an example of a script file I copy/pasted from a copy/paste from a dataflow:

// WS_DATA_CONVERSION
"some-dataflow-id" meta [IsParameterQuery = true, IsParameterQueryRequired = true, Type = type text]

// DF_PM_1_EXTRACT
"some-dataflow-id" meta [IsParameterQuery = true, IsParameterQueryRequired = true, Type = type text]

// DF_EQUIP
"some-dataflow-id" meta [IsParameterQuery = true, IsParameterQueryRequired = true, Type = type any]

// task-id-generator
let
    Source = PowerBI.Dataflows(),
    Workspace = Source{[workspaceId=WS_DATA_CONVERSION]}[Data],
    Dataflow = Workspace{[dataflowId=DF_PM_1_EXTRACT]}[Data],
    Entity = Dataflow{[entity="task-id-generator"]}[Data]
in
    Entity

// EQ/FLOC/ASSY - Cleaned
let
    Source = PowerBI.Dataflows(),
    Workspace = Source{[workspaceId=WS_DATA_CONVERSION]}[Data],
    Dataflow = Workspace{[dataflowId=DF_EQUIP]}[Data],
    Entity = Dataflow{[entity="EQ/FLOC/ASSY - Cleaned"]}[Data]
in
    Entity

The query names are in comments and there is no separation character like ';' between queries which could make it difficult for the language parser to recognize. Though somehow, when pasting this same clipboard content into a Power Query editor the editor recognizes the query names. Even folders are recognized (which are not pasted when pasting the clipboard contents into a text editor for some reason...)