Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/server/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ module ts.server {
var response: T = JSON.parse(responseBody);
}
catch (e) {
throw new Error("Malformed response: Failed to parse server response: " + lastMessage + ". \r\n Error detailes: " + e.message);
throw new Error("Malformed response: Failed to parse server response: " + lastMessage + ". \r\n Error details: " + e.message);
}

// verify the sequence numbers
Expand Down Expand Up @@ -446,6 +446,7 @@ module ts.server {
if (!response.body) {
return undefined;
}

var helpItems: protocol.SignatureHelpItems = response.body;
var span = helpItems.applicableSpan;
var start = this.lineOffsetToPosition(fileName, span.start);
Expand All @@ -465,7 +466,26 @@ module ts.server {
}

getOccurrencesAtPosition(fileName: string, position: number): ReferenceEntry[] {
throw new Error("Not Implemented Yet.");
var lineOffset = this.positionToOneBasedLineOffset(fileName, position);
var args: protocol.FileLocationRequestArgs = {
file: fileName,
line: lineOffset.line,
offset: lineOffset.offset,
};

var request = this.processRequest<protocol.OccurrencesRequest>(CommandNames.Occurrences, args);
var response = this.processResponse<protocol.OccurrencesResponse>(request);

return response.body.map(entry => {
var fileName = entry.file;
var start = this.lineOffsetToPosition(fileName, entry.start);
var end = this.lineOffsetToPosition(fileName, entry.end);
return {
fileName,
textSpan: ts.createTextSpanFromBounds(start, end),
isWriteAccess: entry.isWriteAccess,
};
});
}

getOutliningSpans(fileName: string): OutliningSpan[] {
Expand Down
19 changes: 19 additions & 0 deletions src/server/protocol.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,25 @@ declare module ts.server.protocol {
body?: FileSpan[];
}

/**
* Get occurrences request; value of command field is
* "occurrences". Return response giving spans that are relevant
* in the file at a given line and column.
*/
export interface OccurrencesRequest extends FileLocationRequest {
}

export interface OccurrencesResponseItem extends FileSpan {
/**
* True if the occurrence is a write location, false otherwise.
*/
isWriteAccess: boolean;
}

export interface OccurrencesResponse extends Response {
body?: OccurrencesResponseItem[];
}

/**
* Find references request; value of command field is
* "references". Return response giving the file locations that
Expand Down
146 changes: 79 additions & 67 deletions src/server/session.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="fourslash.ts"/>
/// <reference path="../fourslash.ts"/>

//////curly braces
////module Foo [|{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path='fourslash.ts'/>
/// <reference path="../fourslash.ts"/>

////var x: string[] = [];
////x.forEach(function (y) { y/*1*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="fourslash.ts" />
/// <reference path="../fourslash.ts"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks :)


////class Foo {
////}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path='fourslash.ts'/>
/// <reference path="../fourslash.ts"/>

// @Filename: b.ts
////import n = require('a/*1*/');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path='fourslash.ts' />
/// <reference path="../fourslash.ts"/>

/////**/module Default{var x= ( { } ) ;}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path='fourslash.ts' />
/// <reference path="../fourslash.ts"/>

////switch (1) {
//// case 1:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="fourslash.ts"/>
/// <reference path="../fourslash.ts"/>

////// Interface
////{| "itemName": "IPoint", "kind": "interface", "parentName": "" |}interface IPoint {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="fourslash.ts"/>
/// <reference path="../fourslash.ts"/>

/////// Module
////{| "itemName": "MyShapes", "kind": "module", "parentName": "", "matchKind": "substring" |}module MyShapes {
Expand Down
22 changes: 22 additions & 0 deletions tests/cases/fourslash/server/occurrences01.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// <reference path="../fourslash.ts"/>

////foo: [|switch|] (10) {
//// [|case|] 1:
//// [|case|] 2:
//// [|case|] 3:
//// [|break|];
//// [|break|] foo;
//// continue;
//// continue foo;
////}

let ranges = test.ranges();

for (let r of ranges) {
goTo.position(r.start);
verify.occurrencesAtPositionCount(ranges.length);

for (let range of ranges) {
verify.occurrencesAtPositionContains(range, /*isWriteAccess*/ false);
}
}
16 changes: 16 additions & 0 deletions tests/cases/fourslash/server/occurrences02.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// <reference path="../fourslash.ts"/>

////function [|f|](x: typeof [|f|]) {
//// [|f|]([|f|]);
////}

let ranges = test.ranges();

for (let r of ranges) {
goTo.position(r.start);
verify.occurrencesAtPositionCount(ranges.length);

for (let range of ranges) {
verify.occurrencesAtPositionContains(range);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="fourslash.ts"/>
/// <reference path="../fourslash.ts"/>

////interface One {
//// commonProperty: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path='fourslash.ts'/>
/// <reference path="../fourslash.ts"/>

// Global class reference.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="fourslash.ts" />
/// <reference path="../fourslash.ts"/>

///////<reference path="./Bar.ts" />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="fourslash.ts"/>
/// <reference path="../fourslash.ts"/>

////function foo(data: number) {
////}
Expand Down