Skip to content
Closed
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: 24 additions & 0 deletions Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,20 @@ var serverSources = [
"editorServices.ts",
"protocol.d.ts",
"session.ts",
"nodeimpl.ts",

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.

i do not think you need the extra file if we pass the values as a constructor parameter.

"server.ts"
].map(function (f) {
return path.join(serverDirectory, f);
});

var languageServiceLibrarySources = [

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.

i would concat the services sources as well, to get incremental compilation working correctly.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Alright.

"editorServices.ts",
"protocol.d.ts",
"session.ts"
].map(function (f) {
return path.join(serverDirectory, f);
});

var harnessSources = [
"harness.ts",
"sourceMapRecorder.ts",
Expand Down Expand Up @@ -137,6 +146,7 @@ var harnessSources = [
"protocol.d.ts",
"session.ts",
"client.ts",
"nodeimpl.ts",
"editorServices.ts",
].map(function (f) {
return path.join(serverDirectory, f);
Expand Down Expand Up @@ -369,6 +379,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(serverSources).concat(languageServiceLibrarySources),

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.

you do not need .concat(serverSources), do you?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Aye, good catch. Didn't change that since removing the extra section up above.

/*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, new ts.server.NodeEnvironment(), 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: System;

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 instead of System


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: System, script: string) {
var svc = new ScriptVersionCache();
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
7 changes: 7 additions & 0 deletions src/server/nodeimpl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// <reference path="node.d.ts" />
module ts.server {
export class NodeEnvironment implements Environment {
byteLength = Buffer.byteLength;

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.

these are only used in the session object, i do not see the point of the additional abstraction, just pass them as constructor paramters.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That's pretty much what this is doing, it was just bundling the two parameters into one argument. I'll split it out into multiple arguments.

hrtime = process.hrtime;
}
}
10 changes: 5 additions & 5 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);
constructor(host: ServerHost, env: NodeEnvironment, logger: ts.server.Logger) {
super(host, env, logger);
}

exit() {
Expand Down Expand Up @@ -265,7 +265,7 @@ module ts.server {
}

};
var ioSession = new IOSession(ts.sys, logger);
var ioSession = new IOSession(ts.sys, new NodeEnvironment(), logger);
process.on('uncaughtException', function(err: Error) {
ioSession.logError(err, "unknown");
});
Expand Down
Loading