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

feat: add toPipe and fromPipe commands #182

Merged
merged 9 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,14 @@
{
"command": "extension.expandMacro",
"title": "ElixirLS: Expand macro"
},
{
"command": "extension.toPipe",
"title": "ElixirLS: Convert function call to pipe operator"
},
{
"command": "extension.fromPipe",
"title": "ElixirLS: Convert from pipe operator to function call"
}
],
"menus": {
Expand All @@ -414,7 +422,15 @@
},
{
"command": "extension.expandMacro",
"title": "editorLangId == elixir"
"when": "editorLangId == elixir || editorLangId == eex || editorLangId == html-eex"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at line 415, this seemed to need a fix

},
{
"command": "extension.toPipe",
"when": "editorLangId == elixir || editorLangId == eex || editorLangId == html-eex"
},
{
"command": "extension.fromPipe",
"when": "editorLangId == elixir || editorLangId == eex || editorLangId == html-eex"
}
]
}
Expand Down
38 changes: 37 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,41 @@ function configureExpandMacro(context: ExtensionContext) {
context.subscriptions.push(disposable);
}

function configureManipulatePipes(context: ExtensionContext, operation: "toPipe" | "fromPipe") {
const commandName = `extension.${operation}`;

const disposable = vscode.commands.registerCommand(commandName, async () => {
const extension = vscode.extensions.getExtension("jakebecker.elixir-ls");
const editor = vscode.window.activeTextEditor;
if (!extension || !editor) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the extension check necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not exactly, this just fails faster upon a bizarre error, if that makes sense. I can remove it if you prefer

return;
}

const client = getClient(editor.document);
const uri = editor.document.uri

if (!client) {
return
}


const command = client.initializeResult!.capabilities.executeCommandProvider!.commands
.find((c: string) => c.startsWith('manipulatePipes:'))!;

const uriStr = uri.toString();
const args = [
operation,
uriStr,
editor.selection.start.line,
editor.selection.start.character,
];

const params: ExecuteCommandParams = { command, arguments: args };

client.sendRequest("workspace/executeCommand", params);
});
}

class DebugAdapterExecutableFactory implements vscode.DebugAdapterDescriptorFactory {
createDebugAdapterDescriptor(session: vscode.DebugSession, executable: vscode.DebugAdapterExecutable): vscode.ProviderResult<vscode.DebugAdapterDescriptor> {
if (session.workspaceFolder) {
Expand Down Expand Up @@ -330,7 +365,6 @@ function startClient(context: ExtensionContext, clientOptions: LanguageClientOpt
}

export function activate(context: ExtensionContext): void {
console.warn("activate called");
testElixir();
detectConflictingExtension("mjmcloug.vscode-elixir");
// https://github.com/elixir-lsp/vscode-elixir-ls/issues/34
Expand All @@ -339,6 +373,8 @@ export function activate(context: ExtensionContext): void {
configureRunTestFromCodeLens()
configureCopyDebugInfo(context);
configureExpandMacro(context);
configureManipulatePipes(context, "fromPipe");
configureManipulatePipes(context, "toPipe");
configureDebugger(context);
configureTerminalLinkProvider(context);

Expand Down