[Analyzer] Add optional support for codeOffset/codeLength on navigation targets

Change-Id: Ib328c408d590398d30bd341603781f68f2fd1402
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161166
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Danny Tuppeny 2020-09-02 20:51:27 +00:00 committed by commit-bot@chromium.org
parent a3322ad622
commit 5112f526cf
10 changed files with 170 additions and 40 deletions

View file

@ -109,7 +109,7 @@ a:focus, a:hover {
<body>
<h1>Analysis Server API Specification</h1>
<h1 style="color:#999999">Version
1.28.0
1.29.0
</h1>
<p>
This document contains a specification of the API provided by the
@ -4810,24 +4810,34 @@ a:focus, a:hover {
</dd><dt class="field"><b>offset: int</b></dt><dd>
<p>
The offset of the region to which the user can navigate.
The offset of the name of the target to which the user can navigate.
</p>
</dd><dt class="field"><b>length: int</b></dt><dd>
<p>
The length of the region to which the user can navigate.
The length of the name of the target to which the user can navigate.
</p>
</dd><dt class="field"><b>startLine: int</b></dt><dd>
<p>
The one-based index of the line containing the first character of the
region.
name of the target.
</p>
</dd><dt class="field"><b>startColumn: int</b></dt><dd>
<p>
The one-based index of the column containing the first character of
the region.
the name of the target.
</p>
</dd><dt class="field"><b>codeOffset: int<span style="color:#999999"> (optional)</span></b></dt><dd>
<p>
The offset of the target code to which the user can navigate.
</p>
</dd><dt class="field"><b>codeLength: int<span style="color:#999999"> (optional)</span></b></dt><dd>
<p>
The length of the target code to which the user can navigate.
</p>
</dd></dl></dd><dt class="typeDefinition"><a name="type_Occurrences">Occurrences: object</a></dt><dd>
<p>

View file

@ -6,7 +6,7 @@
// To regenerate the file, use the script
// "pkg/analysis_server/tool/spec/generate_files".
const String PROTOCOL_VERSION = '1.28.0';
const String PROTOCOL_VERSION = '1.29.0';
const String ANALYSIS_NOTIFICATION_ANALYZED_FILES = 'analysis.analyzedFiles';
const String ANALYSIS_NOTIFICATION_ANALYZED_FILES_DIRECTORIES = 'directories';

View file

@ -1119,6 +1119,8 @@ final Matcher isNavigationRegion = LazyMatcher(() => MatchesJsonObject(
/// "length": int
/// "startLine": int
/// "startColumn": int
/// "codeOffset": optional int
/// "codeLength": optional int
/// }
final Matcher isNavigationTarget =
LazyMatcher(() => MatchesJsonObject('NavigationTarget', {
@ -1128,6 +1130,9 @@ final Matcher isNavigationTarget =
'length': isInt,
'startLine': isInt,
'startColumn': isInt
}, optionalFields: {
'codeOffset': isInt,
'codeLength': isInt
}));
/// Occurrences

View file

@ -46,37 +46,49 @@ public class NavigationTarget {
private final int fileIndex;
/**
* The offset of the region to which the user can navigate.
* The offset of the name of the target to which the user can navigate.
*/
private final int offset;
/**
* The length of the region to which the user can navigate.
* The length of the name of the target to which the user can navigate.
*/
private final int length;
/**
* The one-based index of the line containing the first character of the region.
* The one-based index of the line containing the first character of the name of the target.
*/
private final int startLine;
/**
* The one-based index of the column containing the first character of the region.
* The one-based index of the column containing the first character of the name of the target.
*/
private final int startColumn;
/**
* The offset of the target code to which the user can navigate.
*/
private final Integer codeOffset;
/**
* The length of the target code to which the user can navigate.
*/
private final Integer codeLength;
private String file;
/**
* Constructor for {@link NavigationTarget}.
*/
public NavigationTarget(String kind, int fileIndex, int offset, int length, int startLine, int startColumn) {
public NavigationTarget(String kind, int fileIndex, int offset, int length, int startLine, int startColumn, Integer codeOffset, Integer codeLength) {
this.kind = kind;
this.fileIndex = fileIndex;
this.offset = offset;
this.length = length;
this.startLine = startLine;
this.startColumn = startColumn;
this.codeOffset = codeOffset;
this.codeLength = codeLength;
}
@Override
@ -89,7 +101,9 @@ public class NavigationTarget {
other.offset == offset &&
other.length == length &&
other.startLine == startLine &&
other.startColumn == startColumn;
other.startColumn == startColumn &&
ObjectUtilities.equals(other.codeOffset, codeOffset) &&
ObjectUtilities.equals(other.codeLength, codeLength);
}
return false;
}
@ -101,7 +115,9 @@ public class NavigationTarget {
int length = jsonObject.get("length").getAsInt();
int startLine = jsonObject.get("startLine").getAsInt();
int startColumn = jsonObject.get("startColumn").getAsInt();
return new NavigationTarget(kind, fileIndex, offset, length, startLine, startColumn);
Integer codeOffset = jsonObject.get("codeOffset") == null ? null : jsonObject.get("codeOffset").getAsInt();
Integer codeLength = jsonObject.get("codeLength") == null ? null : jsonObject.get("codeLength").getAsInt();
return new NavigationTarget(kind, fileIndex, offset, length, startLine, startColumn, codeOffset, codeLength);
}
public static List<NavigationTarget> fromJsonArray(JsonArray jsonArray) {
@ -120,6 +136,20 @@ public class NavigationTarget {
return file;
}
/**
* The length of the target code to which the user can navigate.
*/
public Integer getCodeLength() {
return codeLength;
}
/**
* The offset of the target code to which the user can navigate.
*/
public Integer getCodeOffset() {
return codeOffset;
}
/**
* The index of the file (in the enclosing navigation response) to navigate to.
*/
@ -135,28 +165,28 @@ public class NavigationTarget {
}
/**
* The length of the region to which the user can navigate.
* The length of the name of the target to which the user can navigate.
*/
public int getLength() {
return length;
}
/**
* The offset of the region to which the user can navigate.
* The offset of the name of the target to which the user can navigate.
*/
public int getOffset() {
return offset;
}
/**
* The one-based index of the column containing the first character of the region.
* The one-based index of the column containing the first character of the name of the target.
*/
public int getStartColumn() {
return startColumn;
}
/**
* The one-based index of the line containing the first character of the region.
* The one-based index of the line containing the first character of the name of the target.
*/
public int getStartLine() {
return startLine;
@ -171,6 +201,8 @@ public class NavigationTarget {
builder.append(length);
builder.append(startLine);
builder.append(startColumn);
builder.append(codeOffset);
builder.append(codeLength);
return builder.toHashCode();
}
@ -186,6 +218,12 @@ public class NavigationTarget {
jsonObject.addProperty("length", length);
jsonObject.addProperty("startLine", startLine);
jsonObject.addProperty("startColumn", startColumn);
if (codeOffset != null) {
jsonObject.addProperty("codeOffset", codeOffset);
}
if (codeLength != null) {
jsonObject.addProperty("codeLength", codeLength);
}
return jsonObject;
}
@ -204,7 +242,11 @@ public class NavigationTarget {
builder.append("startLine=");
builder.append(startLine + ", ");
builder.append("startColumn=");
builder.append(startColumn);
builder.append(startColumn + ", ");
builder.append("codeOffset=");
builder.append(codeOffset + ", ");
builder.append("codeLength=");
builder.append(codeLength);
builder.append("]");
return builder.toString();
}

View file

@ -7,7 +7,7 @@
<body>
<h1>Analysis Server API Specification</h1>
<h1 style="color:#999999">Version
<version>1.28.0</version>
<version>1.29.0</version>
</h1>
<p>
This document contains a specification of the API provided by the

View file

@ -6,7 +6,7 @@
// To regenerate the file, use the script
// "pkg/analysis_server/tool/spec/generate_files".
const String PROTOCOL_VERSION = '1.28.0';
const String PROTOCOL_VERSION = '1.29.0';
const String ANALYSIS_NOTIFICATION_ANALYZED_FILES = 'analysis.analyzedFiles';
const String ANALYSIS_NOTIFICATION_ANALYZED_FILES_DIRECTORIES = 'directories';

View file

@ -1693,24 +1693,34 @@ a:focus, a:hover {
</dd><dt class="field"><b>offset: int</b></dt><dd>
<p>
The offset of the region to which the user can navigate.
The offset of the name of the target to which the user can navigate.
</p>
</dd><dt class="field"><b>length: int</b></dt><dd>
<p>
The length of the region to which the user can navigate.
The length of the name of the target to which the user can navigate.
</p>
</dd><dt class="field"><b>startLine: int</b></dt><dd>
<p>
The one-based index of the line containing the first character of the
region.
name of the target.
</p>
</dd><dt class="field"><b>startColumn: int</b></dt><dd>
<p>
The one-based index of the column containing the first character of
the region.
the name of the target.
</p>
</dd><dt class="field"><b>codeOffset: int<span style="color:#999999"> (optional)</span></b></dt><dd>
<p>
The offset of the target code to which the user can navigate.
</p>
</dd><dt class="field"><b>codeLength: int<span style="color:#999999"> (optional)</span></b></dt><dd>
<p>
The length of the target code to which the user can navigate.
</p>
</dd></dl></dd><dt class="typeDefinition"><a name="type_Occurrences">Occurrences: object</a></dt><dd>
<p>

View file

@ -3690,6 +3690,8 @@ class NavigationRegion implements HasToJson {
/// "length": int
/// "startLine": int
/// "startColumn": int
/// "codeOffset": optional int
/// "codeLength": optional int
/// }
///
/// Clients may not extend, implement or mix-in this class.
@ -3706,6 +3708,10 @@ class NavigationTarget implements HasToJson {
int _startColumn;
int _codeOffset;
int _codeLength;
/// The kind of the element.
ElementKind get kind => _kind;
@ -3726,54 +3732,73 @@ class NavigationTarget implements HasToJson {
_fileIndex = value;
}
/// The offset of the region to which the user can navigate.
/// The offset of the name of the target to which the user can navigate.
int get offset => _offset;
/// The offset of the region to which the user can navigate.
/// The offset of the name of the target to which the user can navigate.
set offset(int value) {
assert(value != null);
_offset = value;
}
/// The length of the region to which the user can navigate.
/// The length of the name of the target to which the user can navigate.
int get length => _length;
/// The length of the region to which the user can navigate.
/// The length of the name of the target to which the user can navigate.
set length(int value) {
assert(value != null);
_length = value;
}
/// The one-based index of the line containing the first character of the
/// region.
/// name of the target.
int get startLine => _startLine;
/// The one-based index of the line containing the first character of the
/// region.
/// name of the target.
set startLine(int value) {
assert(value != null);
_startLine = value;
}
/// The one-based index of the column containing the first character of the
/// region.
/// name of the target.
int get startColumn => _startColumn;
/// The one-based index of the column containing the first character of the
/// region.
/// name of the target.
set startColumn(int value) {
assert(value != null);
_startColumn = value;
}
/// The offset of the target code to which the user can navigate.
int get codeOffset => _codeOffset;
/// The offset of the target code to which the user can navigate.
set codeOffset(int value) {
_codeOffset = value;
}
/// The length of the target code to which the user can navigate.
int get codeLength => _codeLength;
/// The length of the target code to which the user can navigate.
set codeLength(int value) {
_codeLength = value;
}
NavigationTarget(ElementKind kind, int fileIndex, int offset, int length,
int startLine, int startColumn) {
int startLine, int startColumn,
{int codeOffset, int codeLength}) {
this.kind = kind;
this.fileIndex = fileIndex;
this.offset = offset;
this.length = length;
this.startLine = startLine;
this.startColumn = startColumn;
this.codeOffset = codeOffset;
this.codeLength = codeLength;
}
factory NavigationTarget.fromJson(
@ -3820,8 +3845,19 @@ class NavigationTarget implements HasToJson {
} else {
throw jsonDecoder.mismatch(jsonPath, 'startColumn');
}
int codeOffset;
if (json.containsKey('codeOffset')) {
codeOffset =
jsonDecoder.decodeInt(jsonPath + '.codeOffset', json['codeOffset']);
}
int codeLength;
if (json.containsKey('codeLength')) {
codeLength =
jsonDecoder.decodeInt(jsonPath + '.codeLength', json['codeLength']);
}
return NavigationTarget(
kind, fileIndex, offset, length, startLine, startColumn);
kind, fileIndex, offset, length, startLine, startColumn,
codeOffset: codeOffset, codeLength: codeLength);
} else {
throw jsonDecoder.mismatch(jsonPath, 'NavigationTarget', json);
}
@ -3836,6 +3872,12 @@ class NavigationTarget implements HasToJson {
result['length'] = length;
result['startLine'] = startLine;
result['startColumn'] = startColumn;
if (codeOffset != null) {
result['codeOffset'] = codeOffset;
}
if (codeLength != null) {
result['codeLength'] = codeLength;
}
return result;
}
@ -3850,7 +3892,9 @@ class NavigationTarget implements HasToJson {
offset == other.offset &&
length == other.length &&
startLine == other.startLine &&
startColumn == other.startColumn;
startColumn == other.startColumn &&
codeOffset == other.codeOffset &&
codeLength == other.codeLength;
}
return false;
}
@ -3864,6 +3908,8 @@ class NavigationTarget implements HasToJson {
hash = JenkinsSmiHash.combine(hash, length.hashCode);
hash = JenkinsSmiHash.combine(hash, startLine.hashCode);
hash = JenkinsSmiHash.combine(hash, startColumn.hashCode);
hash = JenkinsSmiHash.combine(hash, codeOffset.hashCode);
hash = JenkinsSmiHash.combine(hash, codeLength.hashCode);
return JenkinsSmiHash.finish(hash);
}
}

View file

@ -604,6 +604,8 @@ final Matcher isNavigationRegion = LazyMatcher(() => MatchesJsonObject(
/// "length": int
/// "startLine": int
/// "startColumn": int
/// "codeOffset": optional int
/// "codeLength": optional int
/// }
final Matcher isNavigationTarget =
LazyMatcher(() => MatchesJsonObject('NavigationTarget', {
@ -613,6 +615,9 @@ final Matcher isNavigationTarget =
'length': isInt,
'startLine': isInt,
'startColumn': isInt
}, optionalFields: {
'codeOffset': isInt,
'codeLength': isInt
}));
/// Occurrences

View file

@ -6,7 +6,7 @@
</head>
<body>
<h1>Common Types</h1>
<version>1.1.0</version>
<version>1.2.0</version>
<p>
This document contains a specification of the types that are common between
the analysis server wire protocol and the analysis server plugin wire
@ -1102,27 +1102,39 @@
<field name="offset">
<ref>int</ref>
<p>
The offset of the region to which the user can navigate.
The offset of the name of the target to which the user can navigate.
</p>
</field>
<field name="length">
<ref>int</ref>
<p>
The length of the region to which the user can navigate.
The length of the name of the target to which the user can navigate.
</p>
</field>
<field name="startLine">
<ref>int</ref>
<p>
The one-based index of the line containing the first character of the
region.
name of the target.
</p>
</field>
<field name="startColumn">
<ref>int</ref>
<p>
The one-based index of the column containing the first character of
the region.
the name of the target.
</p>
</field>
<field name="codeOffset" optional="true">
<ref>int</ref>
<p>
The offset of the target code to which the user can navigate.
</p>
</field>
<field name="codeLength" optional="true">
<ref>int</ref>
<p>
The length of the target code to which the user can navigate.
</p>
</field>
</object>