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

Add inline actions for file changes. #738

Merged
merged 5 commits into from Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion package.json
Expand Up @@ -333,7 +333,12 @@
},
{
"command": "pr.openFileInGitHub",
"when": "view =~ /(pr|prStatus)/ && viewItem == filechange"
"when": "view =~ /(pr|prStatus)/ && viewItem =~ /filechange/"
},
{
"command": "review.openFile",
"group": "inline",
"when": "view == prStatus && viewItem =~ /filechange(?!:DELETE)/"
}
],
"editor/title": [
Expand Down
16 changes: 12 additions & 4 deletions src/view/reviewManager.ts
Expand Up @@ -7,7 +7,7 @@ import * as nodePath from 'path';
import * as vscode from 'vscode';
import { parseDiff, parsePatch } from '../common/diffHunk';
import { getDiffLineByPosition, getLastDiffLine, mapCommentsToHead, mapHeadLineToDiffHunkPosition, mapOldPositionToNew, getZeroBased, getAbsolutePosition } from '../common/diffPositionMapping';
import { toReviewUri, fromReviewUri, fromPRUri } from '../common/uri';
import { toReviewUri, fromReviewUri, fromPRUri, ReviewUriParams } from '../common/uri';
import { groupBy, formatError } from '../common/utils';
import { Comment } from '../common/comment';
import { GitChangeType, InMemFileChange } from '../common/file';
Expand Down Expand Up @@ -63,8 +63,16 @@ export class ReviewManager implements vscode.DecorationProvider {
let gitContentProvider = new GitContentProvider(_repository);
gitContentProvider.registerTextDocumentContentFallback(this.provideTextDocumentContent.bind(this));
this._disposables.push(vscode.workspace.registerTextDocumentContentProvider('review', gitContentProvider));
this._disposables.push(vscode.commands.registerCommand('review.openFile', (uri: vscode.Uri) => {
let params = fromReviewUri(uri);
this._disposables.push(vscode.commands.registerCommand('review.openFile', (value: GitFileChangeNode | vscode.Uri) => {
let params: ReviewUriParams;
Copy link
Contributor

Choose a reason for hiding this comment

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

What about files that have been deleted? In the SCM changes view, clicking the "Open File" button on such a change is a no-op, maybe we should do the same instead of having an error notification show up. Or show a warning notification that the file has been deleted

Copy link
Member Author

Choose a reason for hiding this comment

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

Modified the context for file change node to contain GitChangeType info and then we can filter deleted out.

let filePath: string;
if (value instanceof GitFileChangeNode) {
params = fromReviewUri(value.filePath);
filePath = value.filePath.path;
} else {
params = fromReviewUri(value);
filePath = value.path;
}

const activeTextEditor = vscode.window.activeTextEditor;
const opts: vscode.TextDocumentShowOptions = {
Expand All @@ -74,7 +82,7 @@ export class ReviewManager implements vscode.DecorationProvider {

// Check if active text editor has same path as other editor. we cannot compare via
// URI.toString() here because the schemas can be different. Instead we just go by path.
if (activeTextEditor && activeTextEditor.document.uri.path === uri.path) {
if (activeTextEditor && activeTextEditor.document.uri.path === filePath) {
opts.selection = activeTextEditor.selection;
}

Expand Down
2 changes: 1 addition & 1 deletion src/view/treeNodes/fileChangeNode.ts
Expand Up @@ -146,7 +146,7 @@ export class GitFileChangeNode extends TreeNode implements vscode.TreeItem {
public readonly sha?: string,
) {
super();
this.contextValue = 'filechange';
this.contextValue = `filechange:${GitChangeType[status]}`;
this.label = path.basename(fileName);
this.description = path.relative('.', path.dirname(fileName));
this.iconPath = Resource.getFileStatusUri(this);
Expand Down