Skip to content

Commit 8465621

Browse files
author
epriestley
committedMay 20, 2020
Roughly support inline comment suggestions
Summary: Ref T13513. This still has quite a few rough edges and some significant performance isssues, but appears to mostly work. Allow reviewers to "Suggest Edit" on an inline comment and provide replacement text for the highlighted source. Test Plan: Created, edited, reloaded, and submitted inline comments in various states with and without suggestion text. Maniphest Tasks: T13513 Differential Revision: https://secure.phabricator.com/D21276
1 parent 00430fd commit 8465621

18 files changed

+615
-55
lines changed
 

‎resources/celerity/map.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
'core.pkg.css' => 'ba768cdb',
1313
'core.pkg.js' => '845355f4',
1414
'dark-console.pkg.js' => '187792c2',
15-
'differential.pkg.css' => '42a2334f',
16-
'differential.pkg.js' => 'd0ddfb19',
15+
'differential.pkg.css' => 'f924dbcf',
16+
'differential.pkg.js' => '256a327a',
1717
'diffusion.pkg.css' => '42c75c37',
1818
'diffusion.pkg.js' => 'a98c0bf7',
1919
'maniphest.pkg.css' => '35995d6d',
@@ -65,7 +65,7 @@
6565
'rsrc/css/application/differential/add-comment.css' => '7e5900d9',
6666
'rsrc/css/application/differential/changeset-view.css' => '60c3d405',
6767
'rsrc/css/application/differential/core.css' => '7300a73e',
68-
'rsrc/css/application/differential/phui-inline-comment.css' => 'd5749acc',
68+
'rsrc/css/application/differential/phui-inline-comment.css' => '4107254a',
6969
'rsrc/css/application/differential/revision-comment.css' => '7dbc8d1d',
7070
'rsrc/css/application/differential/revision-history.css' => '8aa3eac5',
7171
'rsrc/css/application/differential/revision-list.css' => '93d2df7d',
@@ -381,7 +381,7 @@
381381
'rsrc/js/application/dashboard/behavior-dashboard-tab-panel.js' => '0116d3e8',
382382
'rsrc/js/application/diff/DiffChangeset.js' => '6e5e03d2',
383383
'rsrc/js/application/diff/DiffChangesetList.js' => 'b51ba93a',
384-
'rsrc/js/application/diff/DiffInline.js' => '6fa445ef',
384+
'rsrc/js/application/diff/DiffInline.js' => '829b88bf',
385385
'rsrc/js/application/diff/DiffPathView.js' => '8207abf9',
386386
'rsrc/js/application/diff/DiffTreeView.js' => '5d83623b',
387387
'rsrc/js/application/differential/behavior-diff-radios.js' => '925fe8cd',
@@ -776,7 +776,7 @@
776776
'phabricator-dashboard-css' => '5a205b9d',
777777
'phabricator-diff-changeset' => '6e5e03d2',
778778
'phabricator-diff-changeset-list' => 'b51ba93a',
779-
'phabricator-diff-inline' => '6fa445ef',
779+
'phabricator-diff-inline' => '829b88bf',
780780
'phabricator-diff-path-view' => '8207abf9',
781781
'phabricator-diff-tree-view' => '5d83623b',
782782
'phabricator-drag-and-drop-file-upload' => '4370900d',
@@ -854,7 +854,7 @@
854854
'phui-icon-view-css' => '4cbc684a',
855855
'phui-image-mask-css' => '62c7f4d2',
856856
'phui-info-view-css' => 'a10a909b',
857-
'phui-inline-comment-view-css' => 'd5749acc',
857+
'phui-inline-comment-view-css' => '4107254a',
858858
'phui-invisible-character-view-css' => 'c694c4a4',
859859
'phui-left-right-css' => '68513c34',
860860
'phui-lightbox-css' => '4ebf22da',
@@ -1561,9 +1561,6 @@
15611561
'phabricator-diff-path-view',
15621562
'phuix-button-view',
15631563
),
1564-
'6fa445ef' => array(
1565-
'javelin-dom',
1566-
),
15671564
70245195 => array(
15681565
'javelin-behavior',
15691566
'javelin-stratcom',
@@ -1642,6 +1639,9 @@
16421639
'8207abf9' => array(
16431640
'javelin-dom',
16441641
),
1642+
'829b88bf' => array(
1643+
'javelin-dom',
1644+
),
16451645
83754533 => array(
16461646
'javelin-install',
16471647
'javelin-util',

‎src/__phutil_library_map__.php

+4
Original file line numberDiff line numberDiff line change
@@ -3161,6 +3161,7 @@
31613161
'PhabricatorDeveloperConfigOptions' => 'applications/config/option/PhabricatorDeveloperConfigOptions.php',
31623162
'PhabricatorDeveloperPreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorDeveloperPreferencesSettingsPanel.php',
31633163
'PhabricatorDiffInlineCommentContentState' => 'infrastructure/diff/inline/PhabricatorDiffInlineCommentContentState.php',
3164+
'PhabricatorDiffInlineCommentContext' => 'infrastructure/diff/inline/PhabricatorDiffInlineCommentContext.php',
31643165
'PhabricatorDiffInlineCommentQuery' => 'infrastructure/diff/query/PhabricatorDiffInlineCommentQuery.php',
31653166
'PhabricatorDiffPreferencesSettingsPanel' => 'applications/settings/panel/PhabricatorDiffPreferencesSettingsPanel.php',
31663167
'PhabricatorDiffScopeEngine' => 'infrastructure/diff/PhabricatorDiffScopeEngine.php',
@@ -3594,6 +3595,7 @@
35943595
'PhabricatorInlineComment' => 'infrastructure/diff/interface/PhabricatorInlineComment.php',
35953596
'PhabricatorInlineCommentAdjustmentEngine' => 'infrastructure/diff/engine/PhabricatorInlineCommentAdjustmentEngine.php',
35963597
'PhabricatorInlineCommentContentState' => 'infrastructure/diff/inline/PhabricatorInlineCommentContentState.php',
3598+
'PhabricatorInlineCommentContext' => 'infrastructure/diff/inline/PhabricatorInlineCommentContext.php',
35973599
'PhabricatorInlineCommentController' => 'infrastructure/diff/PhabricatorInlineCommentController.php',
35983600
'PhabricatorInlineCommentInterface' => 'applications/transactions/interface/PhabricatorInlineCommentInterface.php',
35993601
'PhabricatorInlineSummaryView' => 'infrastructure/diff/view/PhabricatorInlineSummaryView.php',
@@ -9630,6 +9632,7 @@
96309632
'PhabricatorDeveloperConfigOptions' => 'PhabricatorApplicationConfigOptions',
96319633
'PhabricatorDeveloperPreferencesSettingsPanel' => 'PhabricatorEditEngineSettingsPanel',
96329634
'PhabricatorDiffInlineCommentContentState' => 'PhabricatorInlineCommentContentState',
9635+
'PhabricatorDiffInlineCommentContext' => 'PhabricatorInlineCommentContext',
96339636
'PhabricatorDiffInlineCommentQuery' => 'PhabricatorApplicationTransactionCommentQuery',
96349637
'PhabricatorDiffPreferencesSettingsPanel' => 'PhabricatorEditEngineSettingsPanel',
96359638
'PhabricatorDiffScopeEngine' => 'Phobject',
@@ -10122,6 +10125,7 @@
1012210125
),
1012310126
'PhabricatorInlineCommentAdjustmentEngine' => 'Phobject',
1012410127
'PhabricatorInlineCommentContentState' => 'Phobject',
10128+
'PhabricatorInlineCommentContext' => 'Phobject',
1012510129
'PhabricatorInlineCommentController' => 'PhabricatorController',
1012610130
'PhabricatorInlineSummaryView' => 'AphrontView',
1012710131
'PhabricatorInstructionsEditField' => 'PhabricatorEditField',

‎src/applications/audit/storage/PhabricatorAuditTransactionComment.php

+11-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ final class PhabricatorAuditTransactionComment
1717
protected $attributes = array();
1818

1919
private $replyToComment = self::ATTACHABLE;
20+
private $inlineContext = self::ATTACHABLE;
2021

2122
public function getApplicationTransactionObject() {
2223
return new PhabricatorAuditTransaction();
@@ -83,12 +84,18 @@ public function setAttribute($key, $value) {
8384
return $this;
8485
}
8586

86-
public function isEmptyInlineComment() {
87-
return !strlen($this->getContent());
88-
}
89-
9087
public function newInlineCommentObject() {
9188
return PhabricatorAuditInlineComment::newFromModernComment($this);
9289
}
9390

91+
public function getInlineContext() {
92+
return $this->assertAttached($this->inlineContext);
93+
}
94+
95+
public function attachInlineContext(
96+
PhabricatorInlineCommentContext $context = null) {
97+
$this->inlineContext = $context;
98+
return $this;
99+
}
100+
94101
}

‎src/applications/differential/controller/DifferentialChangesetViewController.php

+1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ public function handleRequest(AphrontRequest $request) {
200200
->withPublishableComments(true)
201201
->withPublishedComments(true)
202202
->needHidden(true)
203+
->needInlineContext(true)
203204
->execute();
204205

205206
$inlines = mpull($inlines, 'newInlineCommentObject');

‎src/applications/differential/editor/DifferentialRevisionEditEngine.php

+7
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,13 @@ protected function newCommentPreviewContent($object, array $xactions) {
328328
$content = array();
329329

330330
if ($inlines) {
331+
// Reload inlines to get inline context.
332+
$inlines = id(new DifferentialDiffInlineCommentQuery())
333+
->setViewer($viewer)
334+
->withIDs(mpull($inlines, 'getID'))
335+
->needInlineContext(true)
336+
->execute();
337+
331338
$inline_preview = id(new PHUIDiffInlineCommentPreviewListView())
332339
->setViewer($viewer)
333340
->setInlineComments($inlines);

‎src/applications/differential/storage/DifferentialTransactionComment.php

+11-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ final class DifferentialTransactionComment
1818
private $replyToComment = self::ATTACHABLE;
1919
private $isHidden = self::ATTACHABLE;
2020
private $changeset = self::ATTACHABLE;
21+
private $inlineContext = self::ATTACHABLE;
2122

2223
public function getApplicationTransactionObject() {
2324
return new DifferentialTransaction();
@@ -129,12 +130,18 @@ public function setAttribute($key, $value) {
129130
return $this;
130131
}
131132

132-
public function isEmptyInlineComment() {
133-
return !strlen($this->getContent());
134-
}
135-
136133
public function newInlineCommentObject() {
137134
return DifferentialInlineComment::newFromModernComment($this);
138135
}
139136

137+
public function getInlineContext() {
138+
return $this->assertAttached($this->inlineContext);
139+
}
140+
141+
public function attachInlineContext(
142+
PhabricatorInlineCommentContext $context = null) {
143+
$this->inlineContext = $context;
144+
return $this;
145+
}
146+
140147
}

‎src/applications/differential/view/DifferentialChangesetListView.php

+3
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@ public function render() {
373373

374374
'Add new inline comment on selected source text.' =>
375375
pht('Add new inline comment on selected source text.'),
376+
377+
'Suggest Edit' => pht('Suggest Edit'),
378+
'Discard Edit' => pht('Discard Edit'),
376379
),
377380
));
378381

‎src/infrastructure/diff/PhabricatorInlineCommentController.php

+27-5
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ public function processRequest() {
240240

241241
$view = $this->buildScaffoldForView($edit_dialog);
242242

243-
return $this->newInlineResponse($inline, $view);
243+
return $this->newInlineResponse($inline, $view, true);
244244
case 'cancel':
245245
$inline = $this->loadCommentByIDForEdit($this->getCommentID());
246246

@@ -325,6 +325,9 @@ public function processRequest() {
325325

326326
$this->saveComment($inline);
327327

328+
// Reload the inline to attach context.
329+
$inline = $this->loadCommentByIDForEdit($inline->getID());
330+
328331
$edit_dialog = $this->buildEditDialog($inline);
329332

330333
if ($this->getOperation() == 'reply') {
@@ -335,7 +338,7 @@ public function processRequest() {
335338

336339
$view = $this->buildScaffoldForView($edit_dialog);
337340

338-
return $this->newInlineResponse($inline, $view);
341+
return $this->newInlineResponse($inline, $view, true);
339342
}
340343
}
341344

@@ -431,7 +434,7 @@ private function buildRenderedCommentResponse(
431434

432435
$view = $this->buildScaffoldForView($view);
433436

434-
return $this->newInlineResponse($inline, $view);
437+
return $this->newInlineResponse($inline, $view, false);
435438
}
436439

437440
private function buildScaffoldForView(PHUIDiffInlineCommentView $view) {
@@ -446,11 +449,29 @@ private function buildScaffoldForView(PHUIDiffInlineCommentView $view) {
446449

447450
private function newInlineResponse(
448451
PhabricatorInlineComment $inline,
449-
$view) {
452+
$view,
453+
$is_edit) {
454+
455+
if ($inline->getReplyToCommentPHID()) {
456+
$can_suggest = false;
457+
} else {
458+
$can_suggest = (bool)$inline->getInlineContext();
459+
}
460+
461+
if ($is_edit) {
462+
$viewer = $this->getViewer();
463+
$content_state = $inline->getContentStateForEdit($viewer);
464+
} else {
465+
$content_state = $inline->getContentState();
466+
}
467+
468+
$state_map = $content_state->newStorageMap();
450469

451470
$response = array(
452471
'inline' => array(
453472
'id' => $inline->getID(),
473+
'contentState' => $state_map,
474+
'canSuggestEdit' => $can_suggest,
454475
),
455476
'view' => hsprintf('%s', $view),
456477
);
@@ -477,7 +498,8 @@ final protected function loadCommentByIDForEdit($id) {
477498
$viewer = $this->getViewer();
478499

479500
$query = $this->newInlineCommentQuery()
480-
->withIDs(array($id));
501+
->withIDs(array($id))
502+
->needInlineContext(true);
481503

482504
$inline = $this->loadCommentByQuery($query);
483505

‎src/infrastructure/diff/inline/PhabricatorDiffInlineCommentContentState.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function isEmptyContentState() {
1212
}
1313

1414
if ($this->getContentHasSuggestion()) {
15-
if (strlen($this->getSuggestionText())) {
15+
if (strlen($this->getContentSuggestionText())) {
1616
return false;
1717
}
1818
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
final class PhabricatorDiffInlineCommentContext
4+
extends PhabricatorInlineCommentContext {
5+
6+
private $headLines;
7+
private $bodyLines;
8+
private $tailLines;
9+
10+
public function setHeadLines(array $head_lines) {
11+
$this->headLines = $head_lines;
12+
return $this;
13+
}
14+
15+
public function getHeadLines() {
16+
return $this->headLines;
17+
}
18+
19+
public function setBodyLines(array $body_lines) {
20+
$this->bodyLines = $body_lines;
21+
return $this;
22+
}
23+
24+
public function getBodyLines() {
25+
return $this->bodyLines;
26+
}
27+
28+
public function setTailLines(array $tail_lines) {
29+
$this->tailLines = $tail_lines;
30+
return $this;
31+
}
32+
33+
public function getTailLines() {
34+
return $this->tailLines;
35+
}
36+
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
3+
abstract class PhabricatorInlineCommentContext
4+
extends Phobject {}

‎src/infrastructure/diff/interface/PhabricatorInlineComment.php

+4
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ public function setContentState(PhabricatorInlineCommentContentState $state) {
350350
return $this;
351351
}
352352

353+
public function getInlineContext() {
354+
return $this->getStorageObject()->getInlineContext();
355+
}
356+
353357

354358
/* -( PhabricatorMarkupInterface Implementation )-------------------------- */
355359

0 commit comments

Comments
 (0)
Failed to load comments.