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
22 changes: 22 additions & 0 deletions Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ var serverSources = [
return path.join(serverDirectory, f);
});

var languageServiceLibrarySources = [
"editorServices.ts",
"protocol.d.ts",
"session.ts"
].map(function (f) {
return path.join(serverDirectory, f);
}).concat(servicesSources);

var harnessSources = [
"harness.ts",
"sourceMapRecorder.ts",
Expand Down Expand Up @@ -369,6 +377,20 @@ compileFile(servicesFile, servicesSources,[builtLocalDirectory, copyright].conca
var serverFile = path.join(builtLocalDirectory, "tsserver.js");
compileFile(serverFile, serverSources,[builtLocalDirectory, copyright].concat(serverSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true);

var lsslFile = path.join(builtLocalDirectory, "tslssl.js");
compileFile(
lsslFile,
languageServiceLibrarySources,
[builtLocalDirectory, copyright].concat(languageServiceLibrarySources),
/*prefixes*/ [copyright],
/*useBuiltCompiler*/ true,
/*noOutFile*/ false,
/*generateDeclarations*/ true);

// Local target to build the language service server library
desc("Builds language service server library");
task("lssl", [lsslFile]);

// Local target to build the compiler and services
desc("Builds the full compiler and services");
task("local", ["generate-diagnostics", "lib", tscFile, servicesFile, nodeDefinitionsFile, serverFile]);
Expand Down
2 changes: 1 addition & 1 deletion src/harness/harnessLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ module Harness.LanguageService {
// This host is just a proxy for the clientHost, it uses the client
// host to answer server queries about files on disk
var serverHost = new SessionServerHost(clientHost);
var server = new ts.server.Session(serverHost, serverHost);
var server = new ts.server.Session(serverHost, Buffer.byteLength, process.hrtime, serverHost);

// Fake the connection between the client and the server
serverHost.writeMessage = client.onMessage.bind(client);
Expand Down
41 changes: 21 additions & 20 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/// <reference path="..\services\services.ts" />
/// <reference path="protocol.d.ts" />
/// <reference path="session.ts" />
/// <reference path="node.d.ts" />

module ts.server {
export interface Logger {
Expand All @@ -28,15 +27,15 @@ module ts.server {
});
}

class ScriptInfo {
export class ScriptInfo {
svc: ScriptVersionCache;
children: ScriptInfo[] = []; // files referenced by this file
defaultProject: Project; // project to use by default for file
fileWatcher: FileWatcher;
formatCodeOptions = ts.clone(CompilerService.defaultFormatCodeOptions);

constructor(private host: ServerHost, public fileName: string, public content: string, public isOpen = false) {
this.svc = ScriptVersionCache.fromString(content);
this.svc = ScriptVersionCache.fromString(host, content);
}

setFormatOptions(formatOptions: protocol.FormatOptions): void {
Expand Down Expand Up @@ -80,7 +79,7 @@ module ts.server {
}
}

class LSHost implements ts.LanguageServiceHost {
export class LSHost implements ts.LanguageServiceHost {
ls: ts.LanguageService = null;
compilationSettings: ts.CompilerOptions;
filenameToScript: ts.Map<ScriptInfo> = {};
Expand Down Expand Up @@ -273,7 +272,7 @@ module ts.server {
}
}

interface ProjectOptions {
export interface ProjectOptions {
// these fields can be present in the project file
files?: string[];
compilerOptions?: ts.CompilerOptions;
Expand Down Expand Up @@ -376,7 +375,7 @@ module ts.server {
}
}

interface ProjectOpenResult {
export interface ProjectOpenResult {
success?: boolean;
errorMsg?: string;
project?: Project;
Expand All @@ -392,11 +391,11 @@ module ts.server {
return copiedList;
}

interface ProjectServiceEventHandler {
export interface ProjectServiceEventHandler {
(eventName: string, project: Project, fileName: string): void;
}

interface HostConfiguration {
export interface HostConfiguration {
formatCodeOptions: ts.FormatCodeOptions;
hostInfo: string;
}
Expand Down Expand Up @@ -916,7 +915,7 @@ module ts.server {
return rawConfig.error;
}
else {
var parsedCommandLine = ts.parseConfigFile(rawConfig.config, ts.sys, dirPath);
var parsedCommandLine = ts.parseConfigFile(rawConfig.config, this.host, dirPath);
if (parsedCommandLine.errors && (parsedCommandLine.errors.length > 0)) {
return { errorMsg: "tsconfig option errors" };
}
Expand Down Expand Up @@ -953,7 +952,7 @@ module ts.server {

}

class CompilerService {
export class CompilerService {
host: LSHost;
languageService: ts.LanguageService;
classifier: ts.Classifier;
Expand Down Expand Up @@ -985,7 +984,7 @@ module ts.server {
static defaultFormatCodeOptions: ts.FormatCodeOptions = {
IndentSize: 4,
TabSize: 4,
NewLineCharacter: ts.sys.newLine,
NewLineCharacter: ts.sys ? ts.sys.newLine : '\n',
ConvertTabsToSpaces: true,
InsertSpaceAfterCommaDelimiter: true,
InsertSpaceAfterSemicolonInForStatements: true,
Expand All @@ -999,7 +998,7 @@ module ts.server {

}

interface LineCollection {
export interface LineCollection {
charCount(): number;
lineCount(): number;
isLeaf(): boolean;
Expand All @@ -1013,7 +1012,7 @@ module ts.server {
leaf?: LineLeaf;
}

enum CharRangeSection {
export enum CharRangeSection {
PreStart,
Start,
Entire,
Expand All @@ -1022,7 +1021,7 @@ module ts.server {
PostEnd
}

interface ILineIndexWalker {
export interface ILineIndexWalker {
goSubtree: boolean;
done: boolean;
leaf(relativeStart: number, relativeLength: number, lineCollection: LineLeaf): void;
Expand Down Expand Up @@ -1248,7 +1247,7 @@ module ts.server {
}

// text change information
class TextChange {
export class TextChange {
constructor(public pos: number, public deleteLen: number, public insertedText?: string) {
}

Expand All @@ -1263,6 +1262,7 @@ module ts.server {
versions: LineIndexSnapshot[] = [];
minVersion = 0; // no versions earlier than min version will maintain change history
private currentVersion = 0;
private host: ServerHost;

static changeNumberThreshold = 8;
static changeLengthThreshold = 256;
Expand Down Expand Up @@ -1290,7 +1290,7 @@ module ts.server {
}

reloadFromFile(filename: string, cb?: () => any) {
var content = ts.sys.readFile(filename);
var content = this.host.readFile(filename);
this.reload(content);
if (cb)
cb();
Expand Down Expand Up @@ -1360,18 +1360,19 @@ module ts.server {
}
}

static fromString(script: string) {
static fromString(host: ServerHost, script: string) {
var svc = new ScriptVersionCache();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ServerHost

var snap = new LineIndexSnapshot(0, svc);
svc.versions[svc.currentVersion] = snap;
svc.host = host;
snap.index = new LineIndex();
var lm = LineIndex.linesFromText(script);
snap.index.load(lm.lines);
return svc;
}
}

class LineIndexSnapshot implements ts.IScriptSnapshot {
export class LineIndexSnapshot implements ts.IScriptSnapshot {
index: LineIndex;
changesSincePreviousVersion: TextChange[] = [];

Expand Down Expand Up @@ -1605,7 +1606,7 @@ module ts.server {
}
}

class LineNode implements LineCollection {
export class LineNode implements LineCollection {
totalChars = 0;
totalLines = 0;
children: LineCollection[] = [];
Expand Down Expand Up @@ -1891,7 +1892,7 @@ module ts.server {
}
}

class LineLeaf implements LineCollection {
export class LineLeaf implements LineCollection {
udata: any;

constructor(public text: string) {
Expand Down
6 changes: 3 additions & 3 deletions src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module ts.server {
input: process.stdin,
output: process.stdout,
terminal: false,
});
});

class Logger implements ts.server.Logger {
fd = -1;
Expand Down Expand Up @@ -170,11 +170,11 @@ module ts.server {
removeFile(file: WatchedFile) {
this.watchedFiles = WatchedFileSet.copyListRemovingItem(file, this.watchedFiles);
}
}
}

class IOSession extends Session {
constructor(host: ServerHost, logger: ts.server.Logger) {
super(host, logger);
super(host, Buffer.byteLength, process.hrtime, logger);
}

exit() {
Expand Down
22 changes: 13 additions & 9 deletions src/server/session.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/// <reference path="..\compiler\commandLineParser.ts" />
/// <reference path="..\services\services.ts" />
/// <reference path="node.d.ts" />
/// <reference path="protocol.d.ts" />
/// <reference path="editorServices.ts" />

Expand Down Expand Up @@ -61,7 +60,7 @@ module ts.server {
};
}

interface PendingErrorCheck {
export interface PendingErrorCheck {
fileName: string;
project: Project;
}
Expand Down Expand Up @@ -114,11 +113,16 @@ module ts.server {
pendingOperation = false;
fileHash: ts.Map<number> = {};
nextFileId = 1;
errorTimer: NodeJS.Timer;
errorTimer: any; /*NodeJS.Timer | number*/
immediateId: any;
changeSeq = 0;

constructor(private host: ServerHost, private logger: Logger) {
constructor(
private host: ServerHost,
private byteLength: (buf: string, encoding?: string) => number,
private hrtime: (start?: number[]) => number[],
private logger: Logger
) {
this.projectService =
new ProjectService(host, logger, (eventName,project,fileName) => {
this.handleEvent(eventName, project, fileName);
Expand Down Expand Up @@ -149,17 +153,17 @@ module ts.server {
this.host.write(line + this.host.newLine);
}

send(msg: NodeJS._debugger.Message) {
send(msg: protocol.Message) {
var json = JSON.stringify(msg);
if (this.logger.isVerbose()) {
this.logger.info(msg.type + ": " + json);
}
this.sendLineToClient('Content-Length: ' + (1 + Buffer.byteLength(json, 'utf8')) +
this.sendLineToClient('Content-Length: ' + (1 + this.byteLength(json, 'utf8')) +
'\r\n\r\n' + json);
}

event(info: any, eventName: string) {
var ev: NodeJS._debugger.Event = {
var ev: protocol.Event = {
seq: 0,
type: "event",
event: eventName,
Expand Down Expand Up @@ -838,7 +842,7 @@ module ts.server {
onMessage(message: string) {
if (this.logger.isVerbose()) {
this.logger.info("request: " + message);
var start = process.hrtime();
var start = this.hrtime();
}
try {
var request = <protocol.Request>JSON.parse(message);
Expand Down Expand Up @@ -980,7 +984,7 @@ module ts.server {
}

if (this.logger.isVerbose()) {
var elapsed = process.hrtime(start);
var elapsed = this.hrtime(start);
var seconds = elapsed[0]
var nanoseconds = elapsed[1];
var elapsedMs = ((1e9 * seconds) + nanoseconds)/1000000.0;
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/unittests/versionCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ and grew 1cm per day`;
});

it("Edit ScriptVersionCache ", () => {
let svc = server.ScriptVersionCache.fromString(testContent);
let svc = server.ScriptVersionCache.fromString(ts.sys, testContent);
let checkText = testContent;

for (let i = 0; i < iterationCount; i++) {
Expand Down