Respond to code review comments:
* Change comment to say "noresolve=false" in shims.ts05eeba5bc9
* Switch newline to "\r\n"9395eeaedb
* Use hasOwnProperty for Map types212c184602
* Switch "s" to "S" in typescriptServices.ts filename9061e58dff
* Change method names in Node to be more detailed
This commit is contained in:
parent
990669972a
commit
0a206d8855
2
Jakefile
2
Jakefile
|
@ -231,7 +231,7 @@ task("generate-diagnostics", [diagnosticInfoMapTs])
|
||||||
var tcFile = path.join(builtLocalDirectory, "tc.js");
|
var tcFile = path.join(builtLocalDirectory, "tc.js");
|
||||||
compileFile(tcFile, compilerSources, [builtLocalDirectory, copyright].concat(compilerSources), [copyright], /*useBuiltCompiler:*/ false);
|
compileFile(tcFile, compilerSources, [builtLocalDirectory, copyright].concat(compilerSources), [copyright], /*useBuiltCompiler:*/ false);
|
||||||
|
|
||||||
var tcServicesFile = path.join(builtLocalDirectory, "typescriptservices.js");
|
var tcServicesFile = path.join(builtLocalDirectory, "typescriptServices.js");
|
||||||
compileFile(tcServicesFile, servicesSources, [builtLocalDirectory, copyright].concat(servicesSources), [copyright], /*useBuiltCompiler:*/ true);
|
compileFile(tcServicesFile, servicesSources, [builtLocalDirectory, copyright].concat(servicesSources), [copyright], /*useBuiltCompiler:*/ true);
|
||||||
|
|
||||||
// Local target to build the compiler and services
|
// Local target to build the compiler and services
|
||||||
|
|
|
@ -142,6 +142,10 @@ module ts {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function lookUp<T>(map: Map<T>, key: string): T {
|
||||||
|
return hasProperty(map, key) ? map[key] : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
export function mapToArray<T>(map: Map<T>): T[] {
|
export function mapToArray<T>(map: Map<T>): T[] {
|
||||||
var result: T[] = [];
|
var result: T[] = [];
|
||||||
for (var id in map) result.push(map[id]);
|
for (var id in map) result.push(map[id]);
|
||||||
|
|
|
@ -83,7 +83,7 @@ module TypeScript {
|
||||||
|
|
||||||
public addKeys(keys: ts.Map<any>) {
|
public addKeys(keys: ts.Map<any>) {
|
||||||
for (var name in keys) {
|
for (var name in keys) {
|
||||||
if (keys[name]) {
|
if (ts.lookUp(keys, name)) {
|
||||||
this.add(name);
|
this.add(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ module TypeScript.Services {
|
||||||
var parentScope = this.currentScope;
|
var parentScope = this.currentScope;
|
||||||
this.parentScopes.push(parentScope);
|
this.parentScopes.push(parentScope);
|
||||||
|
|
||||||
var scope = parentScope.childScopes[key];
|
var scope = ts.lookUp(parentScope.childScopes, key);
|
||||||
if (!scope) {
|
if (!scope) {
|
||||||
scope = this.createScope()
|
scope = this.createScope()
|
||||||
parentScope.childScopes[key] = scope;
|
parentScope.childScopes[key] = scope;
|
||||||
|
@ -76,7 +76,7 @@ module TypeScript.Services {
|
||||||
private createItem(node: TypeScript.ISyntaxNode, modifiers: ISyntaxToken[], kind: string, name: string): void {
|
private createItem(node: TypeScript.ISyntaxNode, modifiers: ISyntaxToken[], kind: string, name: string): void {
|
||||||
var key = kind + "+" + name;
|
var key = kind + "+" + name;
|
||||||
|
|
||||||
if (this.currentScope.items[key] !== undefined) {
|
if (ts.lookUp(this.currentScope.items, key) !== undefined) {
|
||||||
this.addAdditionalSpan(node, key);
|
this.addAdditionalSpan(node, key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ module TypeScript.Services {
|
||||||
node: TypeScript.ISyntaxNode,
|
node: TypeScript.ISyntaxNode,
|
||||||
key: string) {
|
key: string) {
|
||||||
|
|
||||||
var item = this.currentScope.items[key]
|
var item = ts.lookUp(this.currentScope.items, key);
|
||||||
Debug.assert(item !== undefined);
|
Debug.assert(item !== undefined);
|
||||||
|
|
||||||
var start = TypeScript.start(node);
|
var start = TypeScript.start(node);
|
||||||
|
|
|
@ -32,8 +32,12 @@ module ts {
|
||||||
getChildCount(): number;
|
getChildCount(): number;
|
||||||
getChildAt(index: number): Node;
|
getChildAt(index: number): Node;
|
||||||
getChildren(): Node[];
|
getChildren(): Node[];
|
||||||
|
getStart(): number;
|
||||||
|
getFullStart(): number;
|
||||||
|
getEnd(): number;
|
||||||
|
getWidth(): number;
|
||||||
getFullWidth(): number;
|
getFullWidth(): number;
|
||||||
getTriviaWidth(): number;
|
getLeadingTriviaWidth(): number;
|
||||||
getFullText(): string;
|
getFullText(): string;
|
||||||
getFirstToken(): Node;
|
getFirstToken(): Node;
|
||||||
getLastToken(): Node;
|
getLastToken(): Node;
|
||||||
|
@ -91,16 +95,28 @@ module ts {
|
||||||
return <SourceFile>node;
|
return <SourceFile>node;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getTextPos(): number {
|
public getStart(): number {
|
||||||
return getTokenPosOfNode(this);
|
return getTokenPosOfNode(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getFullWidth(): number {
|
public getFullStart(): number {
|
||||||
return this.end - this.pos;
|
return this.pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getTriviaWidth(): number {
|
public getEnd(): number {
|
||||||
return getTokenPosOfNode(this) - this.pos;
|
return this.end;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getWidth(): number {
|
||||||
|
return this.getStart() - this.getEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
public getFullWidth(): number {
|
||||||
|
return this.end - this.getFullStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
public getLeadingTriviaWidth(): number {
|
||||||
|
return this.getStart() - this.pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getFullText(): string {
|
public getFullText(): string {
|
||||||
|
@ -919,40 +935,48 @@ module ts {
|
||||||
return this._compilationSettings;
|
return this._compilationSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getEntry(filename: string): HostFileInformation {
|
||||||
|
filename = TypeScript.switchToForwardSlashes(filename);
|
||||||
|
return lookUp(this.filenameToEntry, filename);
|
||||||
|
}
|
||||||
|
|
||||||
public contains(filename: string): boolean {
|
public contains(filename: string): boolean {
|
||||||
return !!this.filenameToEntry[TypeScript.switchToForwardSlashes(filename)];
|
return !!this.getEntry(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getHostfilename(filename: string) {
|
public getHostfilename(filename: string) {
|
||||||
var hostCacheEntry = this.filenameToEntry[TypeScript.switchToForwardSlashes(filename)];
|
var hostCacheEntry = this.getEntry(filename);
|
||||||
if (hostCacheEntry) {
|
if (hostCacheEntry) {
|
||||||
return hostCacheEntry.filename;
|
return hostCacheEntry.filename;
|
||||||
}
|
}
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getfilenames(): string[] {
|
public getFilenames(): string[] {
|
||||||
var fileNames: string[] = [];
|
var fileNames: string[] = [];
|
||||||
for (var id in this.filenameToEntry) {
|
|
||||||
fileNames.push(id);
|
forEachKey(this.filenameToEntry, key => {
|
||||||
}
|
if (hasProperty(this.filenameToEntry, key))
|
||||||
|
fileNames.push(key);
|
||||||
|
});
|
||||||
|
|
||||||
return fileNames;
|
return fileNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getVersion(filename: string): number {
|
public getVersion(filename: string): number {
|
||||||
return this.filenameToEntry[TypeScript.switchToForwardSlashes(filename)].version;
|
return this.getEntry(filename).version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public isOpen(filename: string): boolean {
|
public isOpen(filename: string): boolean {
|
||||||
return this.filenameToEntry[TypeScript.switchToForwardSlashes(filename)].isOpen;
|
return this.getEntry(filename).isOpen;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getByteOrderMark(filename: string): ByteOrderMark {
|
public getByteOrderMark(filename: string): ByteOrderMark {
|
||||||
return this.filenameToEntry[TypeScript.switchToForwardSlashes(filename)].byteOrderMark;
|
return this.getEntry(filename).byteOrderMark;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getScriptSnapshot(filename: string): TypeScript.IScriptSnapshot {
|
public getScriptSnapshot(filename: string): TypeScript.IScriptSnapshot {
|
||||||
var file = this.filenameToEntry[TypeScript.switchToForwardSlashes(filename)];
|
var file = this.getEntry(filename);
|
||||||
if (!file.sourceText) {
|
if (!file.sourceText) {
|
||||||
file.sourceText = this.host.getScriptSnapshot(file.filename);
|
file.sourceText = this.host.getScriptSnapshot(file.filename);
|
||||||
}
|
}
|
||||||
|
@ -1117,7 +1141,7 @@ module ts {
|
||||||
|
|
||||||
function getBucketForCompilationSettings(settings: CompilerOptions, createIfMissing: boolean): Map<DocumentRegistryEntry> {
|
function getBucketForCompilationSettings(settings: CompilerOptions, createIfMissing: boolean): Map<DocumentRegistryEntry> {
|
||||||
var key = getKeyFromCompilationSettings(settings);
|
var key = getKeyFromCompilationSettings(settings);
|
||||||
var bucket = buckets[key];
|
var bucket = lookUp(buckets, key);
|
||||||
if (!bucket && createIfMissing) {
|
if (!bucket && createIfMissing) {
|
||||||
buckets[key] = bucket = {};
|
buckets[key] = bucket = {};
|
||||||
}
|
}
|
||||||
|
@ -1126,7 +1150,7 @@ module ts {
|
||||||
|
|
||||||
function reportStats() {
|
function reportStats() {
|
||||||
var bucketInfoArray = Object.keys(buckets).filter(name => name && name.charAt(0) === '_').map(name => {
|
var bucketInfoArray = Object.keys(buckets).filter(name => name && name.charAt(0) === '_').map(name => {
|
||||||
var entries = buckets[name];
|
var entries = lookUp(buckets, name);
|
||||||
var documents: { name: string; refCount: number; references: string[]; }[] = [];
|
var documents: { name: string; refCount: number; references: string[]; }[] = [];
|
||||||
for (var i in entries) {
|
for (var i in entries) {
|
||||||
var entry = entries[i];
|
var entry = entries[i];
|
||||||
|
@ -1152,7 +1176,7 @@ module ts {
|
||||||
referencedFiles: string[]= []): Document {
|
referencedFiles: string[]= []): Document {
|
||||||
|
|
||||||
var bucket = getBucketForCompilationSettings(compilationSettings, /*createIfMissing*/ true);
|
var bucket = getBucketForCompilationSettings(compilationSettings, /*createIfMissing*/ true);
|
||||||
var entry = bucket[filename];
|
var entry = lookUp(bucket, filename);
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
var document = createDocument(compilationSettings, filename, scriptSnapshot, byteOrderMark, version, isOpen, referencedFiles);
|
var document = createDocument(compilationSettings, filename, scriptSnapshot, byteOrderMark, version, isOpen, referencedFiles);
|
||||||
|
|
||||||
|
@ -1179,7 +1203,7 @@ module ts {
|
||||||
|
|
||||||
var bucket = getBucketForCompilationSettings(compilationSettings, /*createIfMissing*/ false);
|
var bucket = getBucketForCompilationSettings(compilationSettings, /*createIfMissing*/ false);
|
||||||
Debug.assert(bucket);
|
Debug.assert(bucket);
|
||||||
var entry = bucket[filename];
|
var entry = lookUp(bucket, filename);
|
||||||
Debug.assert(entry);
|
Debug.assert(entry);
|
||||||
|
|
||||||
if (entry.document.isOpen() === isOpen && entry.document.getVersion() === version) {
|
if (entry.document.isOpen() === isOpen && entry.document.getVersion() === version) {
|
||||||
|
@ -1194,7 +1218,7 @@ module ts {
|
||||||
var bucket = getBucketForCompilationSettings(compilationSettings, false);
|
var bucket = getBucketForCompilationSettings(compilationSettings, false);
|
||||||
Debug.assert(bucket);
|
Debug.assert(bucket);
|
||||||
|
|
||||||
var entry = bucket[filename];
|
var entry = lookUp(bucket, filename);
|
||||||
entry.refCount--;
|
entry.refCount--;
|
||||||
|
|
||||||
Debug.assert(entry.refCount >= 0);
|
Debug.assert(entry.refCount >= 0);
|
||||||
|
@ -1229,10 +1253,14 @@ module ts {
|
||||||
TypeScript.LocalizedDiagnosticMessages = host.getLocalizedDiagnosticMessages();
|
TypeScript.LocalizedDiagnosticMessages = host.getLocalizedDiagnosticMessages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getDocument(filename: string): Document {
|
||||||
|
return lookUp(documentsByName, filename);
|
||||||
|
}
|
||||||
|
|
||||||
function createCompilerHost(): CompilerHost {
|
function createCompilerHost(): CompilerHost {
|
||||||
return {
|
return {
|
||||||
getSourceFile: (filename, languageVersion) => {
|
getSourceFile: (filename, languageVersion) => {
|
||||||
var document = documentsByName[filename];
|
var document = getDocument(filename);
|
||||||
|
|
||||||
Debug.assert(!!document, "document can not be undefined");
|
Debug.assert(!!document, "document can not be undefined");
|
||||||
|
|
||||||
|
@ -1241,7 +1269,7 @@ module ts {
|
||||||
getCancellationToken: () => cancellationToken,
|
getCancellationToken: () => cancellationToken,
|
||||||
getCanonicalFileName: (filename) => useCaseSensitivefilenames ? filename : filename.toLowerCase(),
|
getCanonicalFileName: (filename) => useCaseSensitivefilenames ? filename : filename.toLowerCase(),
|
||||||
useCaseSensitiveFileNames: () => useCaseSensitivefilenames,
|
useCaseSensitiveFileNames: () => useCaseSensitivefilenames,
|
||||||
getNewLine: () => "\n",
|
getNewLine: () => "\r\n",
|
||||||
// Need something that doesn't depend on sys.ts here
|
// Need something that doesn't depend on sys.ts here
|
||||||
getDefaultLibFilename: (): string => {
|
getDefaultLibFilename: (): string => {
|
||||||
throw Error("TOD:: getDefaultLibfilename");
|
throw Error("TOD:: getDefaultLibfilename");
|
||||||
|
@ -1292,7 +1320,7 @@ module ts {
|
||||||
// Now, for every file the host knows about, either add the file (if the compiler
|
// Now, for every file the host knows about, either add the file (if the compiler
|
||||||
// doesn't know about it.). Or notify the compiler about any changes (if it does
|
// doesn't know about it.). Or notify the compiler about any changes (if it does
|
||||||
// know about it.)
|
// know about it.)
|
||||||
var hostfilenames = hostCache.getfilenames();
|
var hostfilenames = hostCache.getFilenames();
|
||||||
|
|
||||||
for (var i = 0, n = hostfilenames.length; i < n; i++) {
|
for (var i = 0, n = hostfilenames.length; i < n; i++) {
|
||||||
var filename = hostfilenames[i];
|
var filename = hostfilenames[i];
|
||||||
|
@ -1301,7 +1329,7 @@ module ts {
|
||||||
var isOpen = hostCache.isOpen(filename);
|
var isOpen = hostCache.isOpen(filename);
|
||||||
var scriptSnapshot = hostCache.getScriptSnapshot(filename);
|
var scriptSnapshot = hostCache.getScriptSnapshot(filename);
|
||||||
|
|
||||||
var document: Document = documentsByName[filename];
|
var document: Document = getDocument(filename);
|
||||||
if (document) {
|
if (document) {
|
||||||
//
|
//
|
||||||
// If the document is the same, assume no update
|
// If the document is the same, assume no update
|
||||||
|
@ -1564,7 +1592,7 @@ module ts {
|
||||||
|
|
||||||
filename = TypeScript.switchToForwardSlashes(filename);
|
filename = TypeScript.switchToForwardSlashes(filename);
|
||||||
|
|
||||||
var document = documentsByName[filename];
|
var document = getDocument(filename);
|
||||||
var sourceUnit = document.getSourceUnit();
|
var sourceUnit = document.getSourceUnit();
|
||||||
|
|
||||||
if (isCompletionListBlocker(document.getSyntaxTree().sourceUnit(), position)) {
|
if (isCompletionListBlocker(document.getSyntaxTree().sourceUnit(), position)) {
|
||||||
|
@ -1706,7 +1734,7 @@ module ts {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
var symbol = activeCompletionSession.symbols[entryName];
|
var symbol = lookUp(activeCompletionSession.symbols, entryName);
|
||||||
if (symbol) {
|
if (symbol) {
|
||||||
var type = session.typeChecker.getTypeOfSymbol(symbol);
|
var type = session.typeChecker.getTypeOfSymbol(symbol);
|
||||||
Debug.assert(type, "Could not find type for symbol");
|
Debug.assert(type, "Could not find type for symbol");
|
||||||
|
@ -1739,7 +1767,7 @@ module ts {
|
||||||
// find the child that has this
|
// find the child that has this
|
||||||
for (var i = 0, n = current.getChildCount(); i < n; i++) {
|
for (var i = 0, n = current.getChildCount(); i < n; i++) {
|
||||||
var child = current.getChildAt(i);
|
var child = current.getChildAt(i);
|
||||||
if (getTokenPosOfNode(child) <= position && position < child.end) {
|
if (child.getStart() <= position && position < child.getEnd()) {
|
||||||
current = child;
|
current = child;
|
||||||
continue outer;
|
continue outer;
|
||||||
}
|
}
|
||||||
|
@ -1824,7 +1852,7 @@ module ts {
|
||||||
synchronizeHostData();
|
synchronizeHostData();
|
||||||
|
|
||||||
filename = TypeScript.switchToForwardSlashes(filename);
|
filename = TypeScript.switchToForwardSlashes(filename);
|
||||||
var document = documentsByName[filename];
|
var document = getDocument(filename);
|
||||||
var node = getNodeAtPosition(document.getSourceFile(), position);
|
var node = getNodeAtPosition(document.getSourceFile(), position);
|
||||||
if (!node) return undefined;
|
if (!node) return undefined;
|
||||||
|
|
||||||
|
|
|
@ -331,7 +331,7 @@ module ts {
|
||||||
|
|
||||||
/// TODO: this should be pushed into VS.
|
/// TODO: this should be pushed into VS.
|
||||||
/// We can not ask the LS instance to resolve, as this will lead to asking the host about files it does not know about,
|
/// We can not ask the LS instance to resolve, as this will lead to asking the host about files it does not know about,
|
||||||
/// something it is not desinged to handle. for now make sure we never get a noresolve=true.
|
/// something it is not desinged to handle. for now make sure we never get a "noresolve == false".
|
||||||
/// This value should not matter, as the host runs resolution logic independentlly
|
/// This value should not matter, as the host runs resolution logic independentlly
|
||||||
options.noResolve = true;
|
options.noResolve = true;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue