Merge remote-tracking branch 'origin/master' into

serverConfigurationMessage.
This commit is contained in:
steveluc
2015-03-17 17:51:16 -07:00
485 changed files with 9597 additions and 2722 deletions

View File

@@ -19,15 +19,19 @@ module ts.server {
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);
}
setFormatOptions(tabSize: number, indentSize: number) {
this.formatCodeOptions.TabSize = tabSize;
this.formatCodeOptions.IndentSize = indentSize;
}
close() {
this.isOpen = false;
}
@@ -153,15 +157,18 @@ module ts.server {
}
}
reloadScript(filename: string, tmpfilename: string, tabSize: number, cb: () => any) {
reloadScript(filename: string, tmpfilename: string, cb: () => any) {
var script = this.getScriptInfo(filename);
if (script) {
script.svc.reloadFromFile(tmpfilename, tabSize, cb);
script.svc.reloadFromFile(tmpfilename, script.formatCodeOptions.TabSize, cb);
}
}
editScript(filename: string, start: number, end: number, newText: string) {
var script = this.getScriptInfo(filename);
if (newText && (newText.length > 0)) {
newText = expandTabs(newText, script.formatCodeOptions.TabSize);
}
if (script) {
script.editContent(start, end, newText);
return;
@@ -365,6 +372,12 @@ module ts.server {
hostInfo: string;
}
export function expandTabs(text: string, tabSize: number) {
var spaces = generateSpaces(tabSize);
return text.replace(/\t/g, spaces);
}
export class ProjectService {
filenameToScriptInfo: ts.Map<ScriptInfo> = {};
// open, non-configured files in two lists
@@ -386,7 +399,13 @@ module ts.server {
}
}
getFormatCodeOptions() {
getFormatCodeOptions(file?: string) {
if (file) {
var info = this.filenameToScriptInfo[file];
if (info) {
return info.formatCodeOptions;
}
}
return this.hostConfiguration.formatCodeOptions;
}
@@ -402,7 +421,7 @@ module ts.server {
}
else {
if (info && (!info.isOpen)) {
info.svc.reloadFromFile(info.fileName, this.hostConfiguration.formatCodeOptions.TabSize);
info.svc.reloadFromFile(info.fileName, info.formatCodeOptions.TabSize);
}
}
}
@@ -412,15 +431,19 @@ module ts.server {
}
setHostConfiguration(args: ts.server.protocol.ConfigureRequestArguments) {
this.hostConfiguration.formatCodeOptions.TabSize = args.tabSize;
this.hostConfiguration.formatCodeOptions.IndentSize = args.indentSize;
this.hostConfiguration.hostInfo = args.hostInfo;
this.log("Host information " + args.hostInfo, "Info");
}
expandTabs(text: string) {
var spaces = generateSpaces(this.hostConfiguration.formatCodeOptions.TabSize);
return text.replace(/\t/g, spaces);
if (args.file) {
var info = this.filenameToScriptInfo[args.file];
if (info) {
info.setFormatOptions(args.tabSize, args.indentSize);
this.log("Host configuration update for file " + args.file + " tab size " + args.tabSize);
}
}
else {
this.hostConfiguration.formatCodeOptions.TabSize = args.tabSize;
this.hostConfiguration.formatCodeOptions.IndentSize = args.indentSize;
this.hostConfiguration.hostInfo = args.hostInfo;
this.log("Host information " + args.hostInfo, "Info");
}
}
closeLog() {
@@ -623,7 +646,7 @@ module ts.server {
/**
* @param filename is absolute pathname
*/
openFile(fileName: string, openedByClient = false) {
openFile(fileName: string, openedByClient: boolean, tabSize?: number) {
fileName = ts.normalizePath(fileName);
var info = ts.lookUp(this.filenameToScriptInfo, fileName);
if (!info) {
@@ -637,12 +660,26 @@ module ts.server {
}
}
if (content !== undefined) {
content = this.expandTabs(content);
var indentSize: number;
if (!tabSize) {
tabSize = this.hostConfiguration.formatCodeOptions.TabSize;
indentSize = this.hostConfiguration.formatCodeOptions.IndentSize;
}
else {
indentSize = tabSize;
}
if (openedByClient) {
this.log("Expanding tabs for file " + fileName + " with tab size " + tabSize.toString());
content = expandTabs(content, tabSize);
}
info = new ScriptInfo(this.host, fileName, content, openedByClient);
this.filenameToScriptInfo[fileName] = info;
if (!info.isOpen) {
info.fileWatcher = this.host.watchFile(fileName, _ => { this.watchedFileChanged(fileName); });
}
else {
info.setFormatOptions(tabSize, indentSize);
}
}
}
if (info) {
@@ -658,9 +695,9 @@ module ts.server {
* @param filename is absolute pathname
*/
openClientFile(filename: string) {
openClientFile(filename: string, tabSize?: number) {
// TODO: tsconfig check
var info = this.openFile(filename, true);
var info = this.openFile(filename, true, tabSize);
this.addOpenFile(info);
this.printProjects();
return info;
@@ -760,7 +797,8 @@ module ts.server {
var normRootFilename = ts.normalizePath(rootFilename);
normRootFilename = getAbsolutePath(normRootFilename, dirPath);
if (this.host.fileExists(normRootFilename)) {
var info = this.openFile(normRootFilename);
// TODO: pass true for file exiplicitly opened
var info = this.openFile(normRootFilename, false);
proj.addRoot(info);
}
else {
@@ -1123,6 +1161,7 @@ module ts.server {
reloadFromFile(filename: string, tabSize: number, cb?: () => any) {
var content = ts.sys.readFile(filename);
content = expandTabs(content, tabSize);
this.reload(content);
if (cb)
cb();

View File

@@ -312,6 +312,10 @@ declare module ts.server.protocol {
* 'Sublime Text version 3075'
*/
hostInfo: string;
/**
* If present, tab settings apply only to this file.
*/
file?: string;
}
/**
@@ -329,6 +333,14 @@ declare module ts.server.protocol {
export interface ConfigureResponse extends Response {
}
/**
* Information found in an "open" request.
*/
export interface OpenRequestArgs extends FileRequestArgs {
/** Initial tab size of file. */
tabSize?: number;
}
/**
* Open request; value of command field is "open". Notify the
* server that the client has file open. The server will not
@@ -337,7 +349,8 @@ declare module ts.server.protocol {
* reload messages) when the file changes. Server does not currently
* send a response to an open request.
*/
export interface OpenRequest extends FileRequest {
export interface OpenRequest extends Request {
arguments: OpenRequestArgs;
}
/**

View File

@@ -5,7 +5,7 @@
/// <reference path="editorServices.ts" />
module ts.server {
var spaceCache = [" ", " ", " ", " "];
var spaceCache:string[] = [];
interface StackTraceError extends Error {
stack?: string;
@@ -397,9 +397,9 @@ module ts.server {
};
}
openClientFile(fileName: string) {
openClientFile(fileName: string, tabSize?: number) {
var file = ts.normalizePath(fileName);
this.projectService.openClientFile(file);
this.projectService.openClientFile(file, tabSize);
}
getQuickInfo(line: number, col: number, fileName: string): protocol.QuickInfoResponseBody {
@@ -441,7 +441,7 @@ module ts.server {
// TODO: avoid duplicate code (with formatonkey)
var edits = compilerService.languageService.getFormattingEditsForRange(file, startPosition, endPosition,
this.projectService.getFormatCodeOptions());
this.projectService.getFormatCodeOptions(file));
if (!edits) {
return undefined;
}
@@ -465,7 +465,7 @@ module ts.server {
var compilerService = project.compilerService;
var position = compilerService.host.lineColToPosition(file, line, col);
var formatOptions = this.projectService.getFormatCodeOptions();
var formatOptions = this.projectService.getFormatCodeOptions(file);
var edits = compilerService.languageService.getFormattingEditsAfterKeystroke(file, position, key,
formatOptions);
// Check whether we should auto-indent. This will be when
@@ -611,8 +611,7 @@ module ts.server {
if (project) {
this.changeSeq++;
// make sure no changes happen before this one is finished
project.compilerService.host.reloadScript(file, tmpfile,
this.projectService.getFormatCodeOptions().TabSize, () => {
project.compilerService.host.reloadScript(file, tmpfile, () => {
this.output(undefined, CommandNames.Reload, reqSeq);
});
}
@@ -756,8 +755,8 @@ module ts.server {
break;
}
case CommandNames.Open: {
var openArgs = <protocol.FileRequestArgs>request.arguments;
this.openClientFile(openArgs.file);
var openArgs = <protocol.OpenRequestArgs>request.arguments;
this.openClientFile(openArgs.file,openArgs.tabSize);
responseRequired = false;
break;
}