Skip to content

Commit

Permalink
fix: Fixed highlights
Browse files Browse the repository at this point in the history
  • Loading branch information
weirongxu committed Dec 19, 2020
1 parent 5d478b6 commit df54786
Show file tree
Hide file tree
Showing 7 changed files with 585 additions and 528 deletions.
31 changes: 16 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,25 @@
"semi": true
},
"devDependencies": {
"@types/jest": "^26.0.14",
"@types/node": "^14.10.3",
"@typescript-eslint/eslint-plugin": "^4.1.1",
"@typescript-eslint/parser": "^4.1.1",
"coc-helper": "^0.6.0",
"@types/jest": "^26.0.19",
"@types/node": "^14.14.14",
"@typescript-eslint/eslint-plugin": "^4.10.0",
"@typescript-eslint/parser": "^4.10.0",
"coc-helper": "^0.7.4",
"coc.nvim": "^0.0.79",
"eslint": "^7.7.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.4",
"jest": "^26.4.2",
"eslint": "^7.16.0",
"eslint-config-prettier": "^7.1.0",
"eslint-plugin-prettier": "^3.3.0",
"jest": "^26.6.3",
"npm-run-all": "^4.1.5",
"prettier": "^2.0.5",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"ts-jest": "^26.3.0",
"ts-loader": "^8.0.2",
"type-fest": "^0.17.0",
"typescript": "^4.0.2",
"vscode-languageserver-protocol": "^3.15.3",
"ts-jest": "^26.4.4",
"ts-loader": "^8.0.12",
"type-fest": "^0.20.2",
"typescript": "^4.1.3",
"vscode-languageserver-protocol": "^3.16.0",
"vscode-languageserver-textdocument": "^1.0.1",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11"
},
Expand Down
17 changes: 8 additions & 9 deletions src/Components/Base.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Disposable, disposeAll, Emitter } from 'coc.nvim';
import { Disposable, disposeAll, Emitter, workspace } from 'coc.nvim';

export abstract class BaseComponent<
Instance,
Options extends object,
InputResult = void
> implements Disposable {
static readonly srcId = workspace.createNameSpace('coc-floatinput');

protected _inited = false;
protected storeOptions?: Options;
protected readonly disposables: Disposable[] = [];
Expand Down Expand Up @@ -33,26 +35,23 @@ export abstract class BaseComponent<
async opened(): Promise<boolean> {
return this._opened(await this.instance());
}
protected abstract async _opened(instance: Instance): Promise<boolean>;
protected abstract _opened(instance: Instance): Promise<boolean>;

protected abstract async _create(): Promise<Instance>;
protected abstract _create(): Promise<Instance>;

async open(options: Options) {
this.storeOptions = options;
return this._open(await this.instance(), options);
}
protected abstract async _open(
instance: Instance,
options: Options,
): Promise<void>;
protected abstract _open(instance: Instance, options: Options): Promise<void>;

async resize() {
if (!this.storeOptions) {
return;
}
return this._resize(await this.instance(), this.storeOptions);
}
protected abstract async _resize(
protected abstract _resize(
instance: Instance,
options: Options,
): Promise<void>;
Expand All @@ -61,7 +60,7 @@ export abstract class BaseComponent<
await this._close(await this.instance(), inputResult);
this.closeEmitter.fire(inputResult);
}
protected abstract async _close(
protected abstract _close(
instance: Instance,
inputResult?: InputResult,
): Promise<void>;
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Confirm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class Confirm<Value extends string = 'yes' | 'no'> extends BaseComponent<
line.forEach((column) => {
void instance.floatWinDict.btn.buffer.addHighlight({
...column,
srcId: 0,
srcId: BaseComponent.srcId,
hlGroup: this.value === column.value ? 'PmenuSel' : 'None',
});
});
Expand Down
8 changes: 4 additions & 4 deletions src/Components/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ export abstract class Input<Value> extends BaseComponent<
> = new Map();
protected static _inited = false;

protected abstract async defaultString(): Promise<string>;
protected abstract defaultString(): Promise<string>;

protected abstract async valueToString(value: Value): Promise<string>;
protected abstract valueToString(value: Value): Promise<string>;

protected abstract async stringToValue(str: string): Promise<Value>;
protected abstract stringToValue(str: string): Promise<Value>;

protected abstract async validateContent(str: string): Promise<boolean>;
protected abstract validateContent(str: string): Promise<boolean>;

protected completionDisposable?: Disposable;
protected id = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/ListProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import {
} from 'coc.nvim';
import {
Position,
TextDocument,
Range,
CompletionItem,
CompletionItemKind,
SymbolInformation,
DocumentSymbol,
} from 'vscode-languageserver-protocol';
} from 'vscode-languageserver-types';
import { TextDocument } from 'vscode-languageserver-textdocument';

type ListItem = { name: string; kind?: CompletionItemKind };

Expand Down
53 changes: 18 additions & 35 deletions src/rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,33 @@ async function getPrepareRename(doc: Document, position: Position) {
return prepare;
}

async function getCurrentWord(doc: Document, position: Position) {
const prepare = await getPrepareRename(doc, position);
if (!prepare) {
return;
}
const word =
'placeholder' in prepare
? prepare.placeholder
: doc.textDocument.getText(prepare);
return word;
}

export async function registerRename(context: ExtensionContext) {
const provider = new CocSymbolProvider();

const input = new StringInput();

async function getCurrentWord(doc: Document) {
async function rename() {
const doc = await workspace.document;
await synchronizeDocument(doc);
if (!hasProviderRename(doc)) {
return false;
return;
}

const position = await workspace.getCursorPosition();

await synchronizeDocument(doc);

const prepare = await getPrepareRename(doc, position);
if (!prepare) {
return false;
}
const word =
'placeholder' in prepare
? prepare.placeholder
: doc.textDocument.getText(prepare);
return word;
}

async function rename() {
const doc = await workspace.document;
const word = await getCurrentWord(doc);

if (word === false) {
const word = await getCurrentWord(doc, position);
if (!word) {
return;
}

Expand All @@ -86,20 +83,6 @@ export async function registerRename(context: ExtensionContext) {
return;
}

const doc = await workspace.document;
if (!hasProviderRename(doc)) {
return;
}

const position = await workspace.getCursorPosition();

await synchronizeDocument(doc);

const prepare = await getPrepareRename(doc, position);
if (!prepare) {
return;
}

const edit = await languages.provideRenameEdits(
doc.textDocument,
position,
Expand Down
Loading

0 comments on commit df54786

Please sign in to comment.