Skip to content

Commit a87b5b9

Browse files
committed
merge the last version of typescript-project-services
1 parent b1e636f commit a87b5b9

File tree

8 files changed

+175
-117
lines changed

8 files changed

+175
-117
lines changed

src/declarations/brackets.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,14 @@ declare module brackets {
10181018

10191019
interface CodeInspection {
10201020
register(languageId: string, provider: InspectionProvider): void;
1021-
Type: { [index: string]: string}
1021+
Type: {
1022+
ERROR: string;
1023+
/** Maintainability issue, probable error / bad smell, etc. */
1024+
WARNING: string;
1025+
/** Inspector unable to continue, code too complex for static analysis, etc. Not counted in error/warning tally. */
1026+
META: string;
1027+
1028+
}
10221029
}
10231030

10241031

src/declarations/typescript-project-services.d.ts

Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ export type TypeScriptInfo = {
258258
typeScript: typeof ts;
259259
libLocation: string;
260260
};
261-
export function createProject(baseDirectory: string, config: TypeScriptProjectConfig, fileSystem: fs.IFileSystem, workingSet: ws.IWorkingSet, defaultLibLocation: string): TypeScriptProject;
261+
export function createProject(documentRegistry: ts.DocumentRegistry, baseDirectory: string, config: TypeScriptProjectConfig, fileSystem: fs.IFileSystem, workingSet: ws.IWorkingSet, defaultLibLocation: string): TypeScriptProject;
262262

263263

264264
}
@@ -590,10 +590,6 @@ import fs = require('typescript-project-services/lib/fileSystem');
590590
import ws = require('typescript-project-services/lib/workingSet');
591591
import project = require('typescript-project-services/lib/project');
592592
import console = require('typescript-project-services/lib/logger');
593-
export type Position = {
594-
line: number;
595-
ch: number;
596-
};
597593
export import Logger = console.Logger;
598594
export var injectLogger: typeof console.injectLogger;
599595
export var injectPromiseLibrary: typeof promise.injectPromiseLibrary;
@@ -630,81 +626,28 @@ export function updateProjectConfigs(configs: {
630626
* dispose the service
631627
*/
632628
export function dispose(): void;
633-
/**
634-
* Represent definition info of a symbol
635-
*/
636-
export type DefinitionInfo = {
637-
/**
638-
* full name of the symbol
639-
*/
640-
name: string;
641-
/**
642-
* line at which the symbol definition start
643-
*/
644-
lineStart: number;
645-
/**
646-
* charachter at which the symbol definition start
647-
*/
648-
charStart: number;
649-
/**
650-
* line at which the symbol definition end
651-
*/
652-
lineEnd: number;
653-
/**
654-
* charachter at which the symbol definition end
655-
*/
656-
charEnd: number;
657-
/**
658-
* path of the file where the symbol is defined
659-
*/
660-
fileName: string;
629+
export type TextSpan = {
630+
start: number;
631+
length: number;
661632
};
662-
/**
663-
* Retrieve definition info of a symbol at a given position in a given file.
664-
* return a promise resolving to a list of definition info.
665-
*
666-
* @param fileName the absolute path of the file
667-
* @param position in the file where you want to retrieve definition info
668-
*
669-
*/
670-
export function getDefinitionAtPosition(fileName: string, position: Position): promise.Promise<DefinitionInfo[]>;
671-
export const enum DiagnosticCategory {
672-
Warning = 0,
673-
Error = 1,
674-
Message = 2,
675-
}
676-
export type TSError = {
677-
pos: Position;
678-
endPos: Position;
679-
message: string;
680-
type: DiagnosticCategory;
633+
export type Diagnostics = {
634+
fileName: string;
635+
start: number;
636+
length: number;
637+
messageText: string;
638+
category: ts.DiagnosticCategory;
639+
code: number;
681640
};
682641
/**
683642
* Retrieve a list of errors for a given file
684643
* return a promise resolving to a list of errors
685644
*
686645
* @param fileName the absolute path of the file
646+
* @param allErrors by default errors are checked in 3 phases, options check, syntax check,
647+
* semantic check, is allErrors is set to false, the service won't check the nex phase
648+
* if there is error in the precedent one
687649
*/
688-
export function getErrorsForFile(fileName: string): promise.Promise<TSError[]>;
689-
export type TextEdit = {
690-
start: number;
691-
end: number;
692-
newText: string;
693-
};
694-
/**
695-
* Retrieve formating information for a givent file.
696-
* return a promise resolving to a list of TextEdit
697-
*
698-
* @param fileName the absolute path of the file
699-
* @param options formation options
700-
* @param startPos an option start position for the formating range
701-
* @param endPos an optional end position for the formating range
702-
*
703-
*/
704-
export function getFormatingForFile(fileName: string, options: ts.FormatCodeOptions, startPos?: Position, endPos?: Position): promise.Promise<TextEdit[]>;
705-
/**
706-
* Represent a completion result
707-
*/
650+
export function getDiagnosticsForFile(fileName: string, allErrors?: boolean): promise.Promise<Diagnostics[]>;
708651
export type CompletionResult = {
709652
/**
710653
* the matched string portion
@@ -725,27 +668,84 @@ export type CompletionResult = {
725668
* @param skip the number of proposition this service should skip
726669
*
727670
*/
728-
export function getCompletionAtPosition(fileName: string, position: Position, limit?: number, skip?: number): promise.Promise<CompletionResult>;
671+
export function getCompletionAtPosition(fileName: string, position: number, limit?: number, skip?: number): promise.Promise<CompletionResult>;
672+
export type QuickInfo = {
673+
kind: string;
674+
kindModifiers: string;
675+
textSpan: TextSpan;
676+
displayParts: ts.SymbolDisplayPart[];
677+
documentation: ts.SymbolDisplayPart[];
678+
};
679+
export function getQuickInfoAtPosition(fileName: string, position: number): promise.Promise<QuickInfo>;
680+
export type SignatureHelpItems = {
681+
items: ts.SignatureHelpItem[];
682+
applicableSpan: TextSpan;
683+
selectedItemIndex: number;
684+
argumentIndex: number;
685+
argumentCount: number;
686+
};
687+
export function getSignatureHelpItems(fileName: string, position: number): promise.Promise<SignatureHelpItems>;
688+
export type RenameInfo = {
689+
canRename: boolean;
690+
localizedErrorMessage: string;
691+
displayName: string;
692+
fullDisplayName: string;
693+
kind: string;
694+
kindModifiers: string;
695+
triggerSpan: TextSpan;
696+
};
697+
export function getRenameInfo(fileName: string, position: number): promise.Promise<RenameInfo>;
698+
export function findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): promise.Promise<{
699+
textSpan: TextSpan;
700+
fileName: string;
701+
}[]>;
702+
export type DefinitionInfo = {
703+
fileName: string;
704+
textSpan: TextSpan;
705+
kind: string;
706+
name: string;
707+
containerKind: string;
708+
containerName: string;
709+
};
710+
export function getDefinitionAtPosition(fileName: string, position: number): promise.Promise<DefinitionInfo[]>;
711+
export type ReferenceEntry = {
712+
textSpan: TextSpan;
713+
fileName: string;
714+
isWriteAccess: boolean;
715+
};
716+
export function getReferencesAtPosition(fileName: string, position: number): promise.Promise<ReferenceEntry[]>;
717+
export function getOccurrencesAtPosition(fileName: string, position: number): promise.Promise<ReferenceEntry[]>;
718+
export type NavigateToItem = {
719+
name: string;
720+
kind: string;
721+
kindModifiers: string;
722+
matchKind: string;
723+
fileName: string;
724+
textSpan: TextSpan;
725+
containerName: string;
726+
containerKind: string;
727+
};
728+
export function getNavigateToItems(fileName: string, search: string): promise.Promise<NavigateToItem[]>;
729729
export type NavigationBarItem = {
730730
text: string;
731731
kind: string;
732732
kindModifiers: string;
733-
positions: {
733+
spans: {
734734
start: number;
735-
end: number;
735+
length: number;
736736
}[];
737737
childItems: NavigationBarItem[];
738738
indent: number;
739739
bolded: boolean;
740740
grayed: boolean;
741741
};
742-
/**
743-
* Retrieve NavigationBarItems
744-
*
745-
* @param fileName the absolute path of the file
746-
*
747-
*/
748742
export function getNavigationBarItems(fileName: string): promise.Promise<NavigationBarItem[]>;
743+
export type TextChange = {
744+
span: TextSpan;
745+
newText: string;
746+
};
747+
export function getFormattingEditsForFile(fileName: string, options: ts.FormatCodeOptions, start: number, end: number): promise.Promise<TextChange[]>;
748+
export function getEmitOutput(fileName: string): promise.Promise<ts.EmitOutput>;
749749

750750

751751
}

src/main/codeHintProvider.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function hasHints(hostEditor: brackets.Editor, implicitChar: string): boo
5151
//TODO we should find a better test here that limits more the implicit request
5252
if (!implicitChar || /[\w.\($_]/.test(implicitChar)) {
5353
editor = hostEditor;
54-
return true;
54+
return true;
5555
}
5656
return false;
5757
}
@@ -68,7 +68,9 @@ export function getHints(implicitChar: string): JQueryDeferred<brackets.HintResu
6868
} else {
6969

7070
ServiceConsumer.getService().then(service => {
71-
service.getCompletionAtPosition(currentFileName, position).then(result => {
71+
var index = editor.indexFromPos(position)
72+
73+
service.getCompletionAtPosition(currentFileName, index).then(result => {
7274
deferred.resolve({
7375
hints: result.entries.map(entry => {
7476
var text = entry.name,

src/main/errorReporter.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414

1515
'use strict';
1616

17-
//TODO that part of the application is not well tested and just 'work' it needs to be refactored
17+
var DocumentManager = brackets.getModule('document/DocumentManager');
18+
var CodeInspection = brackets.getModule('language/CodeInspection');
1819

1920
import ServiceConsumer = require('./serviceConsumer');
2021
import immediate = require('./immediate');
22+
import ts = require('typescript');
2123

2224

2325
//--------------------------------------------------------------------------
@@ -26,6 +28,17 @@ import immediate = require('./immediate');
2628
//
2729
//--------------------------------------------------------------------------
2830

31+
function diagCategoryToType(category: ts.DiagnosticCategory): string {
32+
switch(category) {
33+
case ts.DiagnosticCategory.Message:
34+
return CodeInspection.Type.META;
35+
case ts.DiagnosticCategory.Error:
36+
return CodeInspection.Type.ERROR;
37+
case ts.DiagnosticCategory.Warning:
38+
return CodeInspection.Type.WARNING;
39+
}
40+
}
41+
2942
/**
3043
* TypeScript Inspection Provider
3144
*/
@@ -42,19 +55,23 @@ export function scanFileAsync(content: string, path: string): JQueryPromise<{ er
4255
return $.Deferred(deferred => {
4356
immediate.setImmediate(() => {
4457
ServiceConsumer.getService().then(service => {
45-
service.getErrorsForFile(path).then(
46-
result => {
58+
service.getDiagnosticsForFile(path)
59+
.then(diagnostics => {
60+
var document: any = DocumentManager.getOpenDocumentForPath(path);
61+
document._ensureMasterEditor();
62+
var codeMirror = document._masterEditor._codeMirror;
4763
deferred.resolve({
48-
errors: result,
64+
errors: diagnostics.map(diagnostic => ({
65+
pos: codeMirror.posFromIndex(diagnostic.start),
66+
endPos: codeMirror.posFromIndex(diagnostic.start + diagnostic.length),
67+
message: diagnostic.messageText,
68+
type: diagCategoryToType(diagnostic.category)
69+
})),
4970
aborted: false
5071
});
51-
}, () => {
52-
deferred.resolve({
53-
errors: [],
54-
aborted : false
55-
});
56-
}
57-
);
72+
}, (e) => {
73+
deferred.reject(e);
74+
});
5875
});
5976
});
6077
}).promise();

src/main/formattingManager.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,24 @@ export function format() {
4949
startPos = currentRange ? currentRange.start : undefined,
5050
endPos = currentRange ? currentRange.end : undefined;
5151

52-
if (startPos && endPos && startPos.line === endPos.line && startPos.ch === endPos.ch) {
53-
startPos = endPos = undefined;
54-
}
5552

5653

5754
ServiceConsumer.getService().then(service => {
58-
service.getFormatingForFile(editor.document.file.fullPath, options, startPos, endPos).then(textEdits => {
55+
var start: number;
56+
var end: number;
57+
if (startPos && endPos && (startPos.line !== endPos.line || startPos.ch !== endPos.ch)) {
58+
start = editor.indexFromPos(startPos);
59+
end = editor.indexFromPos(endPos);
60+
}
61+
62+
service.getFormattingEditsForFile(editor.document.file.fullPath, options, start, end).then(textEdits => {
5963
if (EditorManager.getCurrentFullEditor() !== editor) {
6064
return;
6165
}
6266
var pos = editor.getCursorPos();
6367
var scrollPos = editor.getScrollPos();
6468
var newText = textEdits.reduce((text, edit) => {
65-
return text.substr(0, edit.start) + edit.newText + text.substr(edit.end);
69+
return text.substr(0, edit.span.start) + edit.newText + text.substr(edit.span.start + edit.span.length);
6670
}, editor.document.getText());
6771

6872
editor.document.setText(newText);

src/main/inlineEditorProvider.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,21 @@ var DocumentManager = brackets.getModule('document/DocumentManager'),
3535
var deferred = $.Deferred();
3636
ServiceConsumer.getService().then(service => {
3737
var fileName = hostEditor.document.file.fullPath;
38-
service.getDefinitionAtPosition(fileName, pos).then(definitions => {
38+
39+
service.getDefinitionAtPosition(fileName, hostEditor.indexFromPos(pos)).then(definitions => {
3940
if (!definitions || definitions.length === 0) {
4041
deferred.reject();
4142
}
4243

44+
var codeMirror = (<any>hostEditor._codeMirror);
45+
if (codeMirror) {
46+
definitions = definitions.filter(definition =>
47+
definition.fileName !== fileName ||
48+
codeMirror.posFromIndex(definition.textSpan.start).line !== pos.line
49+
);
50+
}
4351

44-
definitions.filter(definition => definition.fileName !== fileName || definition.lineStart !== pos.line);
52+
4553
if (definitions.length === 0) {
4654
deferred.reject();
4755
}
@@ -50,15 +58,22 @@ var DocumentManager = brackets.getModule('document/DocumentManager'),
5058
ranges: brackets.MultiRangeInlineEditorRange[] = [];
5159

5260
definitions.forEach(definition => {
53-
promises.push(DocumentManager.getDocumentForPath(definition.fileName).then(doc => {
54-
ranges.push({
55-
document : doc,
56-
name: definition.name,
57-
lineStart: definition.lineStart,
58-
lineEnd: definition.lineEnd,
59-
fileName: definition.fileName
60-
});
61-
}));
61+
promises.push(
62+
DocumentManager.getDocumentForPath(definition.fileName)
63+
.then(doc => {
64+
(<any>doc)._ensureMasterEditor();
65+
var codeMirror = (<any>doc)._masterEditor._codeMirror;
66+
var lineStart = codeMirror.posFromIndex(definition.textSpan.start).line;
67+
var lineEnd = codeMirror.posFromIndex(definition.textSpan.start + definition.textSpan.length).line
68+
ranges.push({
69+
document : doc,
70+
name: definition.name,
71+
lineStart: lineStart,
72+
lineEnd: lineEnd,
73+
fileName: definition.fileName
74+
});
75+
})
76+
);
6277
});
6378

6479
return $.when.apply($, promises).then(() => {

0 commit comments

Comments
 (0)