Skip to content
This repository was archived by the owner on Aug 13, 2024. It is now read-only.

Commit 935dfaa

Browse files
lgrignontomshen
authored andcommitted
tsconfig.json basic support (#323)
* 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
1 parent 4043dac commit 935dfaa

27 files changed

+1081
-395
lines changed

com.palantir.typescript/.settings/com.palantir.typescript.prefs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,29 @@ build.path.sourceFolder=bridge/src;bridge/typings
33
compiler.codeGenTarget=ECMASCRIPT5
44
compiler.compileOnSave=false
55
compiler.generateDeclarationFiles=false
6+
compiler.inlineSourceMap=false
7+
compiler.inlineSources=false
68
compiler.jsx=NONE
79
compiler.mapSourceFiles=false
810
compiler.moduleGenTarget=NONE
11+
compiler.moduleResolution=CLASSIC
912
compiler.noEmitOnError=true
13+
compiler.noFallthroughCasesInSwitch=false
1014
compiler.noImplicitAny=true
15+
compiler.noImplicitReturns=false
1116
compiler.noLib=false
1217
compiler.outputDirOption=
1318
compiler.outputFileOption=
1419
compiler.removeComments=false
20+
compiler.suppressExcessPropertyErrors=false
1521
compiler.suppressImplicitAnyIndexErrors=false
1622
eclipse.preferences.version=1
1723
editor.indentSize=4
1824
formatter.insertSpaceAfterCommaDelimiter=true
1925
formatter.insertSpaceAfterFunctionKeywordForAnonymousFunctions=false
2026
formatter.insertSpaceAfterKeywordsInControlFlowStatements=true
2127
formatter.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis=false
28+
formatter.insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces=false
2229
formatter.insertSpaceAfterSemicolonInForStatements=true
2330
formatter.insertSpaceBeforeAndAfterBinaryOperators=true
2431
formatter.placeOpenBraceOnNewLineForControlBlocks=false

com.palantir.typescript/bridge/src/fileInfo.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ namespace Bridge {
2424
private contents: string;
2525
private open: boolean;
2626
private path: string;
27+
28+
private projectName: string;
2729

28-
constructor(contents: string, path: string) {
30+
constructor(contents: string, path: string, projectName: string) {
2931
this.changes = [];
3032
this.contents = contents;
3133
this.open = false;
3234
this.path = path;
35+
36+
this.projectName = projectName;
3337
}
3438

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

71+
public getProjectName() {
72+
return this.projectName;
73+
}
74+
6775
public updateFile(contents: string) {
6876
var span = ts.createTextSpan(0, this.contents.length);
6977
var change = ts.createTextChangeRange(span, contents.length);

com.palantir.typescript/bridge/src/languageEndpoint.ts

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,46 +23,39 @@ namespace Bridge {
2323

2424
private documentRegistry: ts.DocumentRegistry;
2525
private exportedFolderNames: { [projectName: string]: string[] };
26-
private fileInfos: { [fileName: string]: FileInfo };
26+
private projectFileInfos: { [projectName: string]: { [fileName: string]: FileInfo } };
27+
private allFileInfos: { [fileName: string]: FileInfo };
2728
private languageServices: { [serviceKey: string]: ts.LanguageService };
28-
private sourceFolderNames: { [projectName: string]: string[] };
2929

3030
constructor() {
3131
this.documentRegistry = ts.createDocumentRegistry();
3232
this.exportedFolderNames = Object.create(null);
33-
this.fileInfos = Object.create(null);
33+
this.allFileInfos = Object.create(null);
3434
this.languageServices = Object.create(null);
35-
this.sourceFolderNames = Object.create(null);
35+
this.projectFileInfos = Object.create(null);
3636
}
3737

3838
public cleanProject(projectName: string) {
3939
if (this.isProjectInitialized(projectName)) {
40-
// delete the project's files
41-
Object.getOwnPropertyNames(this.fileInfos).forEach((fileName) => {
42-
if (this.isSourceFile(projectName, fileName) || this.isExportedFile(projectName, fileName)) {
43-
delete this.fileInfos[fileName];
44-
}
45-
});
4640

4741
delete this.exportedFolderNames[projectName];
42+
delete this.projectFileInfos[projectName];
4843
delete this.languageServices[projectName];
49-
delete this.sourceFolderNames[projectName];
5044
}
5145
}
5246

5347
public initializeProject(
54-
projectName: string,
55-
compilationSettings: ts.CompilerOptions,
56-
referencedProjectNames: string[],
57-
exportedFolderNames: string[],
58-
sourceFolderNames: string[],
59-
files: { [fileName: string]: string }) {
48+
projectName: string,
49+
compilationSettings: ts.CompilerOptions,
50+
referencedProjectNames: string[],
51+
exportedFolderNames: string[],
52+
files: { [fileName: string]: string }) {
6053

6154
this.cleanProject(projectName);
6255
this.exportedFolderNames[projectName] = exportedFolderNames;
63-
this.sourceFolderNames[projectName] = sourceFolderNames;
56+
6457
this.languageServices[projectName] = this.createProjectLanguageService(projectName, compilationSettings, referencedProjectNames);
65-
this.addFiles(files);
58+
this.addFiles(projectName, files);
6659
}
6760

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

75-
this.fileInfos[fileName] = new FileInfo(fileContents, null);
68+
this.allFileInfos[fileName] = new FileInfo(fileContents, null, null);
7669
}
7770

7871
public closeIsolatedLanguageService(serviceKey: string, fileName: string) {
79-
delete this.fileInfos[fileName];
72+
delete this.allFileInfos[fileName];
8073
delete this.languageServices[serviceKey];
8174
}
8275

8376
public getAllTodoComments(projectName: string) {
8477
var todos: { [fileName: string]: TodoCommentEx[] } = {};
85-
Object.keys(this.fileInfos)
86-
.filter((fileName) => this.isSourceFile(projectName, fileName))
78+
Object.keys(this.getProjectFileInfos(projectName))
8779
.forEach((fileName) => {
8880
todos[fileName] = this.getTodoComments(projectName, fileName);
8981
});
@@ -93,8 +85,7 @@ namespace Bridge {
9385
public getAllDiagnostics(projectName: string) {
9486
var diagnostics: { [fileName: string]: DiagnosticEx[] } = Object.create(null);
9587

96-
Object.keys(this.fileInfos)
97-
.filter((fileName) => this.isSourceFile(projectName, fileName))
88+
Object.keys(this.getProjectFileInfos(projectName))
9889
.forEach((fileName) => {
9990
diagnostics[fileName] = this.getDiagnostics(projectName, fileName, true);
10091
});
@@ -103,6 +94,7 @@ namespace Bridge {
10394
}
10495

10596
public getDiagnostics(serviceKey: string, fileName: string, semantic: boolean): DiagnosticEx[] {
97+
10698
var diagnostics = this.languageServices[serviceKey].getSyntacticDiagnostics(fileName);
10799

108100
if (semantic && diagnostics.length === 0) {
@@ -237,11 +229,11 @@ namespace Bridge {
237229
}
238230

239231
public editFile(fileName: string, offset: number, length: number, text: string) {
240-
this.fileInfos[fileName].editContents(offset, length, text);
232+
this.allFileInfos[fileName].editContents(offset, length, text);
241233
}
242234

243235
public setFileOpen(fileName: string, open: boolean) {
244-
var fileInfo = this.fileInfos[fileName];
236+
var fileInfo = this.allFileInfos[fileName];
245237

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

252244
public setLibContents(libContents: string, libES6Contents: string) {
253-
var libFileInfo = new FileInfo(libContents, null);
254-
this.fileInfos[LIB_FILE_NAME] = libFileInfo;
245+
var libFileInfo = new FileInfo(libContents, null, null);
246+
this.allFileInfos[LIB_FILE_NAME] = libFileInfo;
255247

256-
var libES6FileInfo = new FileInfo(libES6Contents, null);
257-
this.fileInfos[LIB_ES6_FILE_NAME] = libES6FileInfo;
248+
var libES6FileInfo = new FileInfo(libES6Contents, null, null);
249+
this.allFileInfos[LIB_ES6_FILE_NAME] = libES6FileInfo;
258250
}
259251

260-
public updateFiles(deltas: IFileDelta[]) {
252+
public updateFiles(projectName: string, deltas: IFileDelta[]) {
261253
deltas.forEach((delta) => {
262254
var fileName = delta.fileName;
263255

264256
switch (delta.delta) {
265257
case "ADDED":
266258
case "CHANGED":
267-
var fileInfo = this.fileInfos[fileName];
259+
var fileInfo = this.allFileInfos[fileName];
268260

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

280-
fileInfo = new FileInfo(contents, filePath);
281-
282-
this.fileInfos[fileName] = fileInfo;
272+
this.pushFile(projectName, fileName, contents, filePath);
283273
}
284274
break;
285275
case "REMOVED":
286-
delete this.fileInfos[fileName];
276+
var fileInfo: FileInfo = this.allFileInfos[fileName];
277+
if (fileInfo != null) {
278+
delete this.allFileInfos[fileName];
279+
if (fileInfo.getProjectName() != null) {
280+
delete this.getProjectFileInfos(fileInfo.getProjectName())[fileName];
281+
}
282+
}
287283
break;
288284
}
289285
});
290286
}
291287

292-
private addFiles(files: { [fileName: string]: string }) {
288+
private addFiles(projectName: string, files: { [fileName: string]: string }) {
293289
for (var fileName in files) {
294290
if (files.hasOwnProperty(fileName)) {
295291
var filePath = files[fileName];
@@ -303,14 +299,29 @@ namespace Bridge {
303299
}
304300

305301
// cache the file
306-
var fileInfo = new FileInfo(contents, filePath);
307-
this.fileInfos[fileName] = fileInfo;
302+
this.pushFile(projectName, fileName, contents, filePath);
308303
}
309304
}
310305
}
311306

312-
private createLanguageService(compilationSettings: ts.CompilerOptions, fileFilter: (fileName: string) => boolean) {
313-
var host = new LanguageServiceHost(compilationSettings, fileFilter, this.fileInfos);
307+
private pushFile(projectName: string, fileName: string, contents: string, filePath: string): void {
308+
var fileInfo = new FileInfo(contents, filePath, projectName);
309+
this.getProjectFileInfos(projectName)[fileName] = fileInfo;
310+
this.allFileInfos[fileName] = fileInfo;
311+
}
312+
313+
private getProjectFileInfos(projectName: string): { [fileName: string]: FileInfo } {
314+
if (this.projectFileInfos[projectName] == null) {
315+
this.projectFileInfos[projectName] = Object.create(null);
316+
}
317+
318+
return this.projectFileInfos[projectName];
319+
}
320+
321+
private createLanguageService(
322+
compilationSettings: ts.CompilerOptions,
323+
fileFilter: (fileName: string) => boolean) {
324+
var host = new LanguageServiceHost(compilationSettings, fileFilter, this.allFileInfos);
314325

315326
return ts.createLanguageService(host, this.documentRegistry);
316327
}
@@ -351,9 +362,8 @@ namespace Bridge {
351362
}
352363

353364
private isSourceFile(projectName: string, fileName: string) {
354-
return this.sourceFolderNames[projectName].some((sourceFolderName) => {
355-
return folderContains(sourceFolderName, fileName);
356-
});
365+
var projectSourceFiles: { [fileName: string]: FileInfo } = this.getProjectFileInfos(projectName);
366+
return projectSourceFiles[fileName] != null;
357367
}
358368
}
359369

com.palantir.typescript/bridge/src/languageServiceHost.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ namespace Bridge {
5757
}
5858

5959
public getScriptFileNames() {
60-
return Object.getOwnPropertyNames(this.fileInfos).filter(this.fileFilter);
60+
var fileNames: string[] = Object.getOwnPropertyNames(this.fileInfos);
61+
if (this.fileFilter != null) {
62+
fileNames = fileNames.filter(this.fileFilter);
63+
}
64+
65+
return fileNames;
6166
}
6267

6368
public getScriptSnapshot(fileName: string) {

com.palantir.typescript/src/com/palantir/typescript/Builders.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import org.eclipse.core.runtime.IStatus;
2828
import org.eclipse.core.runtime.Status;
2929
import org.eclipse.core.runtime.jobs.Job;
30+
import org.eclipse.jface.dialogs.IDialogConstants;
31+
import org.eclipse.jface.dialogs.MessageDialog;
32+
import org.eclipse.swt.widgets.Shell;
3033

3134
import com.google.common.collect.ImmutableList;
3235

@@ -37,6 +40,38 @@
3740
*/
3841
public final class Builders {
3942

43+
/**
44+
* Prompts user to rebuild either the project or the whole workspace.
45+
*
46+
* @param shell
47+
* parent shell
48+
* @param onlyProject
49+
* the project to be rebuilt or null if the whole workpsace has to be rebuilt
50+
* @return true if user accepted the recompilation
51+
*/
52+
public static boolean promptRecompile(Shell shell, IProject onlyProject) {
53+
String title = Resources.BUNDLE.getString("preferences.compiler.rebuild.dialog.title");
54+
String message = Resources.BUNDLE.getString("preferences.compiler.rebuild.dialog.message");
55+
String[] buttonLabels = new String[] { IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL, IDialogConstants.YES_LABEL };
56+
MessageDialog dialog = new MessageDialog(shell, title, null, message, MessageDialog.QUESTION, buttonLabels, 2);
57+
int result = dialog.open();
58+
59+
boolean process = false;
60+
if (result != 1) { // cancel
61+
process = true;
62+
63+
// rebuild the workspace
64+
if (result == 2) {
65+
if (onlyProject != null) {
66+
Builders.rebuildProject(onlyProject);
67+
} else {
68+
Builders.rebuildWorkspace();
69+
}
70+
}
71+
}
72+
return process;
73+
}
74+
4075
/**
4176
* Forces a full clean/rebuild of all the workspace project that have the TypeScript nature.
4277
*/

com.palantir.typescript/src/com/palantir/typescript/IPreferenceConstants.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
*/
2525
public interface IPreferenceConstants {
2626

27+
String BUILD_PATH_EXCLUDE = "build.path.exclude";
2728
String BUILD_PATH_EXPORTED_FOLDER = "build.path.exportedFolder";
29+
String BUILD_PATH_FILES = "build.path.files";
30+
String BUILD_PATH_INCLUDE = "build.path.include";
2831
String BUILD_PATH_SOURCE_FOLDER = "build.path.sourceFolder";
2932

3033
String COMPILER_TARGET = "compiler.codeGenTarget";
@@ -45,6 +48,7 @@ public interface IPreferenceConstants {
4548
String COMPILER_OUT_DIR = "compiler.outputDirOption";
4649
String COMPILER_OUT_FILE = "compiler.outputFileOption";
4750
String COMPILER_REMOVE_COMMENTS = "compiler.removeComments";
51+
String COMPILER_EMIT_DECORATOR_METADATA = "compiler.emitDecoratorMetadata";
4852
String COMPILER_SUPPRESS_EXCESS_PROPERTY_ERRORS = "compiler.suppressExcessPropertyErrors";
4953
String COMPILER_SUPPRESS_IMPLICIT_ANY_INDEX_ERRORS = "compiler.suppressImplicitAnyIndexErrors";
5054

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

7276
String GENERAL_NODE_PATH = "general.nodePath";
77+
String GENERAL_USE_TSCONFIG_FILE = "general.useTsConfigFile";
7378

7479
String SYNTAX_COLORING_COMMENT_COLOR = "syntaxColoring.comment.color";
7580
String SYNTAX_COLORING_IDENTIFIER_COLOR = "syntaxColoring.identifier.color";
@@ -79,4 +84,7 @@ public interface IPreferenceConstants {
7984
String SYNTAX_COLORING_PUNCTUATION_COLOR = "syntaxColoring.punctuation.color";
8085
String SYNTAX_COLORING_REG_EXP_LITERAL_COLOR = "syntaxColoring.regExpLiteral.color";
8186
String SYNTAX_COLORING_STRING_LITERAL_COLOR = "syntaxColoring.stringLiteral.color";
87+
88+
String PREFERENCE_STORE_TS_CONFIG_LAST_MODIFICATION_TIME = "preferenceStore.tsConfigLastModTime";
89+
String PREFERENCE_STORE_TS_CONFIG_HASH = "preferenceStore.tsConfigHash";
8290
}

0 commit comments

Comments
 (0)