Skip to content

Commit

Permalink
Fix selection by using coc API (#60)
Browse files Browse the repository at this point in the history
* Fix selection to use coc api

* delete old method
  • Loading branch information
TylerLeonhardt authored Jul 30, 2019
1 parent 3ec4b05 commit bd4a4e7
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,20 @@ import settings = require("./settings");
import * as process from './process';
import { EvaluateRequestMessage, IEvaluateRequestArguments } from "./messages";

async function getCurrentSelection(mode: string) {
let doc = await workspace.document

if (mode === "v" || mode === "V") {
let [from, _ ] = await doc.buffer.mark("<")
let [to, __ ] = await doc.buffer.mark(">")
let result: string[] = []
for(let i = from; i <= to; ++i)
{
result.push(doc.getline(i - 1))
}
return result
}
else if (mode === "n") {
let line = await workspace.nvim.call('line', '.')
return [doc.getline(line - 1)]
}
else if (mode === "i") {
// TODO what to do in insert mode?
}
else if (mode === "t") {
//TODO what to do in terminal mode?
async function getSelectedTextToExecute(mode: string): Promise<string> {
let doc = workspace.getDocument(workspace.bufnr);
if (!doc) return "";

if (mode === 'n') {
// get whole line.
let range = await workspace.getCursorPosition();
if (range) return doc.getline(range.line);
} else {
let range = await workspace.getSelectedRange(mode, doc);
if (range) return doc.textDocument.getText(range);
}

return []
return "";
}

function startREPLProc(context: ExtensionContext, config: settings.ISettings, pwshPath: string, title: string) {
Expand Down Expand Up @@ -81,9 +70,7 @@ function startREPLProc(context: ExtensionContext, config: settings.ISettings, pw
return
}

// TODO: move to workspace.getCurrentSelection when we get an answer:
// https://github.com/neoclide/coc.nvim/issues/933
const content = (await getCurrentSelection(mode)).join("\n");
const content = await getSelectedTextToExecute(mode);

const evaluateArgs: IEvaluateRequestArguments = {
expression: content,
Expand Down

0 comments on commit bd4a4e7

Please sign in to comment.