Skip to content

Commit

Permalink
Rename getReferenceAtPosition result vars
Browse files Browse the repository at this point in the history
  • Loading branch information
svsool committed Jul 21, 2020
1 parent 0266b25 commit 96a6ddd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/commands/openReferenceInDefaultApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ const openReferenceInDefaultApp = async () => {
const activeTextEditor = vscode.window.activeTextEditor;

if (activeTextEditor) {
const refResult = getReferenceAtPosition(
const refAtPos = getReferenceAtPosition(
activeTextEditor.document,
activeTextEditor.selection.start,
);

if (refResult) {
const uri = findUriByRef(getWorkspaceCache().allUris, refResult.ref);
if (refAtPos) {
const uri = findUriByRef(getWorkspaceCache().allUris, refAtPos.ref);

if (uri) {
open(uri.fsPath);
Expand Down
6 changes: 3 additions & 3 deletions src/extensions/ReferenceHoverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export default class ReferenceHoverProvider implements vscode.HoverProvider {

const imagePreviewMaxHeight = Math.max(getConfigProperty('imagePreviewMaxHeight', 200), 10);

const refResult = getReferenceAtPosition(document, position);
const refAtPos = getReferenceAtPosition(document, position);

if (refResult) {
const { ref, range } = refResult;
if (refAtPos) {
const { ref, range } = refAtPos;
const uris = getWorkspaceCache().allUris;

const foundUri = findUriByRef(uris, ref);
Expand Down
6 changes: 3 additions & 3 deletions src/extensions/ReferenceProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export default class ReferenceProvider implements vscode.ReferenceProvider {
return [];
}

const refResult = getReferenceAtPosition(document, position);
const refAtPos = getReferenceAtPosition(document, position);

return refResult
? (await findReferences(refResult.ref, [document.uri.fsPath])).map(({ location }) => location)
return refAtPos
? (await findReferences(refAtPos.ref, [document.uri.fsPath])).map(({ location }) => location)
: [];
}
}
16 changes: 7 additions & 9 deletions src/extensions/ReferenceRenameProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,20 @@ export default class ReferenceRenameProvider implements RenameProvider {
document: TextDocument,
position: Position,
): ProviderResult<Range | { range: Range; placeholder: string }> {
const refDef = getReferenceAtPosition(document, position);
const refAtPos = getReferenceAtPosition(document, position);

if (refDef) {
const { range, ref, label } = refDef;
if (refAtPos) {
const { range, ref } = refAtPos;

if (!findUriByRef(getWorkspaceCache().allUris, ref)) {
throw new Error(
'Rename is not available for nonexistent links. Create file first by clicking on the link.',
);
}

// TODO: Labels don't work well for refs with multiple |||
// needs testing and fixes
return new Range(
new Position(range.start.line, range.start.character + 2),
new Position(range.end.line, range.end.character - 2 - label.length),
new Position(range.start.line, range.start.character + 2 + ref.length),
);
}

Expand All @@ -49,10 +47,10 @@ export default class ReferenceRenameProvider implements RenameProvider {
position: Position,
newName: string,
): ProviderResult<WorkspaceEdit> {
const refDef = getReferenceAtPosition(document, position);
const refAtPos = getReferenceAtPosition(document, position);

if (refDef) {
const { ref } = refDef;
if (refAtPos) {
const { ref } = refAtPos;

const workspaceEdit = new WorkspaceEdit();

Expand Down
4 changes: 2 additions & 2 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,11 @@ export const ensureDirectoryExistence = (filePath: string) => {
export const getRefUriUnderCursor = (): vscode.Uri | null | undefined => {
const activeTextEditor = vscode.window.activeTextEditor;

const refResult =
const refAtPos =
activeTextEditor &&
getReferenceAtPosition(activeTextEditor.document, activeTextEditor.selection.start);

return refResult && findUriByRef(getWorkspaceCache().allUris, refResult.ref);
return refAtPos && findUriByRef(getWorkspaceCache().allUris, refAtPos.ref);
};

export const parseRef = (rawRef: string): RefT => {
Expand Down

0 comments on commit 96a6ddd

Please sign in to comment.