Skip to content

Commit

Permalink
tsconfig.json basic support (#323)
Browse files Browse the repository at this point in the history
* tsconfig file could be read if requested, and applied to parameters

* fixed project recompile

* moved prompt recompilation

* prompts to recompile on use tsconfig check

* force reload button + added more efficient enum values mapping

* fixed error on maven compile + fixed checkstyle warning

* added emitDecoratorMetadata option

* tsconfig "files" works with file and directories

* fixed exclude list + reset tsconfig preferences on reload to avoid files/include/exclude persistence

* disabled source folder field if tsconfig enabled

* take palantir's feedbacks in account + fix some bugs

* * fixed empty sources set bug * fixed compileOnSave blocking problem * fixed languageEndPoint missing ref

* fixed pref store
  • Loading branch information
lgrignon authored and tomshen committed Sep 20, 2016
1 parent 4043dac commit 935dfaa
Show file tree
Hide file tree
Showing 27 changed files with 1,081 additions and 395 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,29 @@ build.path.sourceFolder=bridge/src;bridge/typings
compiler.codeGenTarget=ECMASCRIPT5
compiler.compileOnSave=false
compiler.generateDeclarationFiles=false
compiler.inlineSourceMap=false
compiler.inlineSources=false
compiler.jsx=NONE
compiler.mapSourceFiles=false
compiler.moduleGenTarget=NONE
compiler.moduleResolution=CLASSIC
compiler.noEmitOnError=true
compiler.noFallthroughCasesInSwitch=false
compiler.noImplicitAny=true
compiler.noImplicitReturns=false
compiler.noLib=false
compiler.outputDirOption=
compiler.outputFileOption=
compiler.removeComments=false
compiler.suppressExcessPropertyErrors=false
compiler.suppressImplicitAnyIndexErrors=false
eclipse.preferences.version=1
editor.indentSize=4
formatter.insertSpaceAfterCommaDelimiter=true
formatter.insertSpaceAfterFunctionKeywordForAnonymousFunctions=false
formatter.insertSpaceAfterKeywordsInControlFlowStatements=true
formatter.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis=false
formatter.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces=false
formatter.insertSpaceAfterSemicolonInForStatements=true
formatter.insertSpaceBeforeAndAfterBinaryOperators=true
formatter.placeOpenBraceOnNewLineForControlBlocks=false
Expand Down
10 changes: 9 additions & 1 deletion com.palantir.typescript/bridge/src/fileInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ namespace Bridge {
private contents: string;
private open: boolean;
private path: string;

private projectName: string;

constructor(contents: string, path: string) {
constructor(contents: string, path: string, projectName: string) {
this.changes = [];
this.contents = contents;
this.open = false;
this.path = path;

this.projectName = projectName;
}

public editContents(offset: number, length: number, text: string): void {
Expand Down Expand Up @@ -64,6 +68,10 @@ namespace Bridge {
return this.changes.length.toString(10);
}

public getProjectName() {
return this.projectName;
}

public updateFile(contents: string) {
var span = ts.createTextSpan(0, this.contents.length);
var change = ts.createTextChangeRange(span, contents.length);
Expand Down
100 changes: 55 additions & 45 deletions com.palantir.typescript/bridge/src/languageEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,46 +23,39 @@ namespace Bridge {

private documentRegistry: ts.DocumentRegistry;
private exportedFolderNames: { [projectName: string]: string[] };
private fileInfos: { [fileName: string]: FileInfo };
private projectFileInfos: { [projectName: string]: { [fileName: string]: FileInfo } };
private allFileInfos: { [fileName: string]: FileInfo };
private languageServices: { [serviceKey: string]: ts.LanguageService };
private sourceFolderNames: { [projectName: string]: string[] };

constructor() {
this.documentRegistry = ts.createDocumentRegistry();
this.exportedFolderNames = Object.create(null);
this.fileInfos = Object.create(null);
this.allFileInfos = Object.create(null);
this.languageServices = Object.create(null);
this.sourceFolderNames = Object.create(null);
this.projectFileInfos = Object.create(null);
}

public cleanProject(projectName: string) {
if (this.isProjectInitialized(projectName)) {
// delete the project's files
Object.getOwnPropertyNames(this.fileInfos).forEach((fileName) => {
if (this.isSourceFile(projectName, fileName) || this.isExportedFile(projectName, fileName)) {
delete this.fileInfos[fileName];
}
});

delete this.exportedFolderNames[projectName];
delete this.projectFileInfos[projectName];
delete this.languageServices[projectName];
delete this.sourceFolderNames[projectName];
}
}

public initializeProject(
projectName: string,
compilationSettings: ts.CompilerOptions,
referencedProjectNames: string[],
exportedFolderNames: string[],
sourceFolderNames: string[],
files: { [fileName: string]: string }) {
projectName: string,
compilationSettings: ts.CompilerOptions,
referencedProjectNames: string[],
exportedFolderNames: string[],
files: { [fileName: string]: string }) {

this.cleanProject(projectName);
this.exportedFolderNames[projectName] = exportedFolderNames;
this.sourceFolderNames[projectName] = sourceFolderNames;

this.languageServices[projectName] = this.createProjectLanguageService(projectName, compilationSettings, referencedProjectNames);
this.addFiles(files);
this.addFiles(projectName, files);
}

public isProjectInitialized(projectName: string) {
Expand All @@ -72,18 +65,17 @@ namespace Bridge {
public initializeIsolatedLanguageService(serviceKey: string, fileName: string, fileContents: string) {
this.languageServices[serviceKey] = this.createIsolatedLanguageService(fileName);

this.fileInfos[fileName] = new FileInfo(fileContents, null);
this.allFileInfos[fileName] = new FileInfo(fileContents, null, null);
}

public closeIsolatedLanguageService(serviceKey: string, fileName: string) {
delete this.fileInfos[fileName];
delete this.allFileInfos[fileName];
delete this.languageServices[serviceKey];
}

public getAllTodoComments(projectName: string) {
var todos: { [fileName: string]: TodoCommentEx[] } = {};
Object.keys(this.fileInfos)
.filter((fileName) => this.isSourceFile(projectName, fileName))
Object.keys(this.getProjectFileInfos(projectName))
.forEach((fileName) => {
todos[fileName] = this.getTodoComments(projectName, fileName);
});
Expand All @@ -93,8 +85,7 @@ namespace Bridge {
public getAllDiagnostics(projectName: string) {
var diagnostics: { [fileName: string]: DiagnosticEx[] } = Object.create(null);

Object.keys(this.fileInfos)
.filter((fileName) => this.isSourceFile(projectName, fileName))
Object.keys(this.getProjectFileInfos(projectName))
.forEach((fileName) => {
diagnostics[fileName] = this.getDiagnostics(projectName, fileName, true);
});
Expand All @@ -103,6 +94,7 @@ namespace Bridge {
}

public getDiagnostics(serviceKey: string, fileName: string, semantic: boolean): DiagnosticEx[] {

var diagnostics = this.languageServices[serviceKey].getSyntacticDiagnostics(fileName);

if (semantic && diagnostics.length === 0) {
Expand Down Expand Up @@ -237,11 +229,11 @@ namespace Bridge {
}

public editFile(fileName: string, offset: number, length: number, text: string) {
this.fileInfos[fileName].editContents(offset, length, text);
this.allFileInfos[fileName].editContents(offset, length, text);
}

public setFileOpen(fileName: string, open: boolean) {
var fileInfo = this.fileInfos[fileName];
var fileInfo = this.allFileInfos[fileName];

// the file may have been deleted previously, so only process this call if the file exists
if (fileInfo != null) {
Expand All @@ -250,21 +242,21 @@ namespace Bridge {
}

public setLibContents(libContents: string, libES6Contents: string) {
var libFileInfo = new FileInfo(libContents, null);
this.fileInfos[LIB_FILE_NAME] = libFileInfo;
var libFileInfo = new FileInfo(libContents, null, null);
this.allFileInfos[LIB_FILE_NAME] = libFileInfo;

var libES6FileInfo = new FileInfo(libES6Contents, null);
this.fileInfos[LIB_ES6_FILE_NAME] = libES6FileInfo;
var libES6FileInfo = new FileInfo(libES6Contents, null, null);
this.allFileInfos[LIB_ES6_FILE_NAME] = libES6FileInfo;
}

public updateFiles(deltas: IFileDelta[]) {
public updateFiles(projectName: string, deltas: IFileDelta[]) {
deltas.forEach((delta) => {
var fileName = delta.fileName;

switch (delta.delta) {
case "ADDED":
case "CHANGED":
var fileInfo = this.fileInfos[fileName];
var fileInfo = this.allFileInfos[fileName];

if (fileInfo !== undefined) {
// only update files not currently open in an editor
Expand All @@ -277,19 +269,23 @@ namespace Bridge {
var filePath = delta.filePath;
var contents = readFileContents(filePath);

fileInfo = new FileInfo(contents, filePath);

this.fileInfos[fileName] = fileInfo;
this.pushFile(projectName, fileName, contents, filePath);
}
break;
case "REMOVED":
delete this.fileInfos[fileName];
var fileInfo: FileInfo = this.allFileInfos[fileName];
if (fileInfo != null) {
delete this.allFileInfos[fileName];
if (fileInfo.getProjectName() != null) {
delete this.getProjectFileInfos(fileInfo.getProjectName())[fileName];
}
}
break;
}
});
}

private addFiles(files: { [fileName: string]: string }) {
private addFiles(projectName: string, files: { [fileName: string]: string }) {
for (var fileName in files) {
if (files.hasOwnProperty(fileName)) {
var filePath = files[fileName];
Expand All @@ -303,14 +299,29 @@ namespace Bridge {
}

// cache the file
var fileInfo = new FileInfo(contents, filePath);
this.fileInfos[fileName] = fileInfo;
this.pushFile(projectName, fileName, contents, filePath);
}
}
}

private createLanguageService(compilationSettings: ts.CompilerOptions, fileFilter: (fileName: string) => boolean) {
var host = new LanguageServiceHost(compilationSettings, fileFilter, this.fileInfos);
private pushFile(projectName: string, fileName: string, contents: string, filePath: string): void {
var fileInfo = new FileInfo(contents, filePath, projectName);
this.getProjectFileInfos(projectName)[fileName] = fileInfo;
this.allFileInfos[fileName] = fileInfo;
}

private getProjectFileInfos(projectName: string): { [fileName: string]: FileInfo } {
if (this.projectFileInfos[projectName] == null) {
this.projectFileInfos[projectName] = Object.create(null);
}

return this.projectFileInfos[projectName];
}

private createLanguageService(
compilationSettings: ts.CompilerOptions,
fileFilter: (fileName: string) => boolean) {
var host = new LanguageServiceHost(compilationSettings, fileFilter, this.allFileInfos);

return ts.createLanguageService(host, this.documentRegistry);
}
Expand Down Expand Up @@ -351,9 +362,8 @@ namespace Bridge {
}

private isSourceFile(projectName: string, fileName: string) {
return this.sourceFolderNames[projectName].some((sourceFolderName) => {
return folderContains(sourceFolderName, fileName);
});
var projectSourceFiles: { [fileName: string]: FileInfo } = this.getProjectFileInfos(projectName);
return projectSourceFiles[fileName] != null;
}
}

Expand Down
7 changes: 6 additions & 1 deletion com.palantir.typescript/bridge/src/languageServiceHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ namespace Bridge {
}

public getScriptFileNames() {
return Object.getOwnPropertyNames(this.fileInfos).filter(this.fileFilter);
var fileNames: string[] = Object.getOwnPropertyNames(this.fileInfos);
if (this.fileFilter != null) {
fileNames = fileNames.filter(this.fileFilter);
}

return fileNames;
}

public getScriptSnapshot(fileName: string) {
Expand Down
35 changes: 35 additions & 0 deletions com.palantir.typescript/src/com/palantir/typescript/Builders.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;

import com.google.common.collect.ImmutableList;

Expand All @@ -37,6 +40,38 @@
*/
public final class Builders {

/**
* Prompts user to rebuild either the project or the whole workspace.
*
* @param shell
* parent shell
* @param onlyProject
* the project to be rebuilt or null if the whole workpsace has to be rebuilt
* @return true if user accepted the recompilation
*/
public static boolean promptRecompile(Shell shell, IProject onlyProject) {
String title = Resources.BUNDLE.getString("preferences.compiler.rebuild.dialog.title");
String message = Resources.BUNDLE.getString("preferences.compiler.rebuild.dialog.message");
String[] buttonLabels = new String[] { IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL, IDialogConstants.YES_LABEL };
MessageDialog dialog = new MessageDialog(shell, title, null, message, MessageDialog.QUESTION, buttonLabels, 2);
int result = dialog.open();

boolean process = false;
if (result != 1) { // cancel
process = true;

// rebuild the workspace
if (result == 2) {
if (onlyProject != null) {
Builders.rebuildProject(onlyProject);
} else {
Builders.rebuildWorkspace();
}
}
}
return process;
}

/**
* Forces a full clean/rebuild of all the workspace project that have the TypeScript nature.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
*/
public interface IPreferenceConstants {

String BUILD_PATH_EXCLUDE = "build.path.exclude";
String BUILD_PATH_EXPORTED_FOLDER = "build.path.exportedFolder";
String BUILD_PATH_FILES = "build.path.files";
String BUILD_PATH_INCLUDE = "build.path.include";
String BUILD_PATH_SOURCE_FOLDER = "build.path.sourceFolder";

String COMPILER_TARGET = "compiler.codeGenTarget";
Expand All @@ -45,6 +48,7 @@ public interface IPreferenceConstants {
String COMPILER_OUT_DIR = "compiler.outputDirOption";
String COMPILER_OUT_FILE = "compiler.outputFileOption";
String COMPILER_REMOVE_COMMENTS = "compiler.removeComments";
String COMPILER_EMIT_DECORATOR_METADATA = "compiler.emitDecoratorMetadata";
String COMPILER_SUPPRESS_EXCESS_PROPERTY_ERRORS = "compiler.suppressExcessPropertyErrors";
String COMPILER_SUPPRESS_IMPLICIT_ANY_INDEX_ERRORS = "compiler.suppressImplicitAnyIndexErrors";

Expand All @@ -70,6 +74,7 @@ public interface IPreferenceConstants {
String FORMATTER_PLACE_OPEN_BRACE_ON_NEW_LINE_FOR_FUNCTIONS = "formatter.placeOpenBraceOnNewLineForFunctions";

String GENERAL_NODE_PATH = "general.nodePath";
String GENERAL_USE_TSCONFIG_FILE = "general.useTsConfigFile";

String SYNTAX_COLORING_COMMENT_COLOR = "syntaxColoring.comment.color";
String SYNTAX_COLORING_IDENTIFIER_COLOR = "syntaxColoring.identifier.color";
Expand All @@ -79,4 +84,7 @@ public interface IPreferenceConstants {
String SYNTAX_COLORING_PUNCTUATION_COLOR = "syntaxColoring.punctuation.color";
String SYNTAX_COLORING_REG_EXP_LITERAL_COLOR = "syntaxColoring.regExpLiteral.color";
String SYNTAX_COLORING_STRING_LITERAL_COLOR = "syntaxColoring.stringLiteral.color";

String PREFERENCE_STORE_TS_CONFIG_LAST_MODIFICATION_TIME = "preferenceStore.tsConfigLastModTime";
String PREFERENCE_STORE_TS_CONFIG_HASH = "preferenceStore.tsConfigHash";
}
Loading

0 comments on commit 935dfaa

Please sign in to comment.