Skip to content

Commit

Permalink
Remove "key.offset" and "key.length" from results of `dictWithComment…
Browse files Browse the repository at this point in the history
…MarkNamesCursorInfo()`

Their values are same with "key.nameoffset" and "key.namelength" in most case.
When kind is extension, their values locate **the type's declaration** in their declared file.
That may be different from the file declaring extension.

So, using them is wrong.
Is this related to realm/jazzy#454?
  • Loading branch information
norio-nomura committed Jun 10, 2016
1 parent 1008fcc commit 16b5c17
Show file tree
Hide file tree
Showing 4 changed files with 252 additions and 245 deletions.
9 changes: 8 additions & 1 deletion Source/SourceKittenFramework/File.swift
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,13 @@ public final class File {

// Skip kinds, since values from editor.open are more accurate than cursorinfo
updateDict.removeValueForKey(SwiftDocKey.Kind.rawValue)

// Skip offset and length.
// Their values are same with "key.nameoffset" and "key.namelength" in most case.
// When kind is extension, their values locate **the type's declaration** in their declared file.
// That may be different from the file declaring extension.
updateDict.removeValueForKey(SwiftDocKey.Offset.rawValue)
updateDict.removeValueForKey(SwiftDocKey.Length.rawValue)
return updateDict
}
return nil
Expand All @@ -275,7 +282,7 @@ public final class File {
private func shouldInsert(parent: [String: SourceKitRepresentable], offset: Int64) -> Bool {
return SwiftDocKey.getSubstructure(parent) != nil &&
((offset == 0) ||
(shouldTreatAsSameFile(parent) && SwiftDocKey.getOffset(parent) == offset))
(shouldTreatAsSameFile(parent) && SwiftDocKey.getNameOffset(parent) == offset))
}

/**
Expand Down
48 changes: 24 additions & 24 deletions Tests/SourceKittenFramework/Fixtures/Bicycle.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
},
{
"key.kind" : "source.lang.swift.decl.class",
"key.offset" : 238,
"key.offset" : 232,
"key.parsed_declaration" : "public class Bicycle",
"key.doc.comment" : "🚲 A two-wheeled, human-powered mode of transportation.",
"key.namelength" : 7,
"key.doc.line" : 8,
"key.bodylength" : 2222,
"key.length" : 7,
"key.length" : 2238,
"key.doc.column" : 14,
"key.parsed_scope.end" : 93,
"key.usr" : "s:C7Bicycle7Bicycle",
Expand All @@ -54,13 +54,13 @@
"key.substructure" : [
{
"key.kind" : "source.lang.swift.decl.enum",
"key.offset" : 484,
"key.offset" : 479,
"key.parsed_declaration" : "public enum Style",
"key.doc.comment" : "Frame and construction style.\n\n- Road: For streets or trails.\n- Touring: For long journeys.\n- Cruiser: For casual trips around town.\n- Hybrid: For general-purpose transportation.",
"key.namelength" : 5,
"key.doc.line" : 17,
"key.bodylength" : 49,
"key.length" : 5,
"key.length" : 62,
"key.doc.column" : 17,
"key.parsed_scope.end" : 19,
"key.usr" : "s:OC7Bicycle7Bicycle5Style",
Expand Down Expand Up @@ -165,13 +165,13 @@
},
{
"key.kind" : "source.lang.swift.decl.enum",
"key.offset" : 723,
"key.offset" : 718,
"key.parsed_declaration" : "public enum Gearing",
"key.doc.comment" : "Mechanism for converting pedal power into motion.\n\n- Fixed: A single, fixed gear.\n- Freewheel: A variable-speed, disengageable gear.",
"key.namelength" : 7,
"key.doc.line" : 27,
"key.bodylength" : 60,
"key.length" : 7,
"key.length" : 75,
"key.doc.column" : 17,
"key.parsed_scope.end" : 30,
"key.usr" : "s:OC7Bicycle7Bicycle7Gearing",
Expand Down Expand Up @@ -226,7 +226,7 @@
"key.offset" : 765,
"key.parsed_declaration" : "case Freewheel(speeds: Int)",
"key.namelength" : 9,
"key.length" : 9,
"key.length" : 22,
"key.name" : "Freewheel",
"key.typename" : "Bicycle.Gearing.Type -> (speeds: Int) -> Bicycle.Gearing",
"key.parsed_scope.end" : 29,
Expand All @@ -253,13 +253,13 @@
},
{
"key.kind" : "source.lang.swift.decl.enum",
"key.offset" : 997,
"key.offset" : 992,
"key.parsed_declaration" : "enum Handlebar",
"key.doc.comment" : "Hardware used for steering.\n\n- Riser: A casual handlebar.\n- Café: An upright handlebar.\n- Drop: A classic handlebar.\n- Bullhorn: A powerful handlebar.",
"key.namelength" : 9,
"key.doc.line" : 40,
"key.bodylength" : 47,
"key.length" : 9,
"key.length" : 64,
"key.doc.column" : 10,
"key.parsed_scope.end" : 42,
"key.usr" : "s:OC7Bicycle7Bicycle9Handlebar",
Expand Down Expand Up @@ -364,12 +364,12 @@
},
{
"key.kind" : "source.lang.swift.decl.var.instance",
"key.offset" : 1100,
"key.offset" : 1096,
"key.parsed_declaration" : "let style: Style",
"key.doc.comment" : "The style of the bicycle.",
"key.namelength" : 5,
"key.doc.line" : 45,
"key.length" : 5,
"key.length" : 16,
"key.doc.declaration" : "let style: Bicycle.Bicycle.Style",
"key.typename" : "Bicycle.Style",
"key.name" : "style",
Expand All @@ -393,12 +393,12 @@
},
{
"key.kind" : "source.lang.swift.decl.var.instance",
"key.offset" : 1158,
"key.offset" : 1154,
"key.parsed_declaration" : "let gearing: Gearing",
"key.doc.comment" : "The gearing of the bicycle.",
"key.namelength" : 7,
"key.doc.line" : 48,
"key.length" : 7,
"key.length" : 20,
"key.doc.declaration" : "let gearing: Bicycle.Bicycle.Gearing",
"key.typename" : "Bicycle.Gearing",
"key.name" : "gearing",
Expand All @@ -422,12 +422,12 @@
},
{
"key.kind" : "source.lang.swift.decl.var.instance",
"key.offset" : 1222,
"key.offset" : 1218,
"key.parsed_declaration" : "let handlebar: Handlebar",
"key.doc.comment" : "The handlebar of the bicycle.",
"key.namelength" : 9,
"key.doc.line" : 51,
"key.length" : 9,
"key.length" : 24,
"key.doc.declaration" : "let handlebar: Bicycle.Bicycle.Handlebar",
"key.typename" : "Bicycle.Handlebar",
"key.name" : "handlebar",
Expand All @@ -451,12 +451,12 @@
},
{
"key.kind" : "source.lang.swift.decl.var.instance",
"key.offset" : 1299,
"key.offset" : 1295,
"key.parsed_declaration" : "let frameSize: Int",
"key.doc.comment" : "The size of the frame, in centimeters.",
"key.namelength" : 9,
"key.doc.line" : 54,
"key.length" : 9,
"key.length" : 18,
"key.doc.declaration" : "let frameSize: Int",
"key.typename" : "Int",
"key.name" : "frameSize",
Expand All @@ -480,12 +480,12 @@
},
{
"key.kind" : "source.lang.swift.decl.var.instance",
"key.offset" : 1390,
"key.offset" : 1386,
"key.parsed_declaration" : "private(set) var numberOfTrips: Int",
"key.doc.comment" : "The number of trips travelled by the bicycle.",
"key.namelength" : 13,
"key.doc.line" : 57,
"key.length" : 13,
"key.length" : 22,
"key.doc.declaration" : "private(set) var numberOfTrips: Int",
"key.typename" : "Int",
"key.name" : "numberOfTrips",
Expand All @@ -510,12 +510,12 @@
},
{
"key.kind" : "source.lang.swift.decl.var.instance",
"key.offset" : 1495,
"key.offset" : 1491,
"key.parsed_declaration" : "private(set) var distanceTravelled: Double",
"key.doc.comment" : "The total distance travelled by the bicycle, in meters.",
"key.namelength" : 17,
"key.doc.line" : 60,
"key.length" : 17,
"key.length" : 29,
"key.doc.declaration" : "private(set) var distanceTravelled: Double",
"key.typename" : "Double",
"key.name" : "distanceTravelled",
Expand Down Expand Up @@ -546,7 +546,7 @@
"key.namelength" : 86,
"key.doc.line" : 72,
"key.bodylength" : 192,
"key.length" : 86,
"key.length" : 281,
"key.doc.parameters" : [
{
"name" : "style",
Expand Down Expand Up @@ -613,13 +613,13 @@
},
{
"key.kind" : "source.lang.swift.decl.function.method.instance",
"key.offset" : 2322,
"key.offset" : 2317,
"key.parsed_declaration" : "func travel(distance meters: Double)",
"key.doc.comment" : "Take a bike out for a spin.\n\n- parameter meters: The distance to travel in meters.",
"key.namelength" : 31,
"key.doc.line" : 87,
"key.bodylength" : 112,
"key.length" : 31,
"key.length" : 151,
"key.doc.parameters" : [
{
"name" : "meters",
Expand Down
Loading

0 comments on commit 16b5c17

Please sign in to comment.