-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to easily get diagnostics.
- Loading branch information
Showing
19 changed files
with
405 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
/obj | ||
/temp | ||
/bin | ||
/dist-cg | ||
*.suo | ||
*.csproj | ||
*.csproj.user | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
/node_modules | ||
/coverage | ||
/.vscode | ||
/code-generation | ||
/src | ||
*.js.map | ||
/obj | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
title: Expressions | ||
--- | ||
|
||
## Expression With Type Arguments | ||
|
||
These are found in certain areas. For example `extends` and `implements` expressions. | ||
|
||
### Getting expression | ||
|
||
```typescript | ||
// returns: ts.LeftHandSideExpression | ||
const expression = expressionWithTypeArgs.getExpression(); // returns: Node | ||
``` | ||
|
||
### Getting type arguments | ||
|
||
```typescript | ||
const typeArgs = expressionWithTypeArgs.getTypeArguments(); // returns: TypeNode[] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
--- | ||
title: Diagnostics | ||
--- | ||
|
||
## Diagnostics | ||
|
||
Diagnostics (compile errors) can be retrieved on the AST or on source files by using the `.getDiagnostics()` method: | ||
|
||
```typescript | ||
const diagnostics = ast.getDiagnostics(); | ||
``` | ||
|
||
Calling it on a source file will only give you the diagnostics for that source file. | ||
|
||
### Diagnostic | ||
|
||
#### Message text | ||
|
||
Returned message text could be a `string` or a `DiagnosticMessageChain`: | ||
|
||
```typescript | ||
const message = diagnostic.getMessageText(); | ||
``` | ||
|
||
#### Source file | ||
|
||
Source file the diagnostic occurs in: | ||
|
||
```typescript | ||
const sourceFile = diagnostic.getSourceFile(); | ||
``` | ||
|
||
#### Start & length | ||
|
||
Position in the file and length of the diagnostic: | ||
|
||
```typescript | ||
const start = diagnostic.getStart(); // returns: number | ||
const length = diagnostic.getLength(); // returns: number | ||
``` | ||
|
||
#### Category | ||
|
||
Categories can be warnings, errors, or just messages. | ||
|
||
```typescript | ||
const category = diagnostic.getCategory(); // returns: ts.DiagnosticCategory | ||
``` | ||
|
||
#### Code | ||
|
||
This is the error code number: | ||
|
||
```typescript | ||
const code = diagnostic.getCode(); // returns: number | ||
``` | ||
|
||
#### Source | ||
|
||
```typescript | ||
const source = diagnostic.getSource(); // returns: string | undefined | ||
``` | ||
|
||
### DiagnosticMessageChain | ||
|
||
A diagnostic message chain (DMC) will be returned by `diagnostic.getMessageText()` in certain scenarios. | ||
|
||
According to the typescript compiler: | ||
|
||
``` | ||
/** | ||
* A linked list of formatted diagnostic messages to be used as part of a multiline message. | ||
* It is built from the bottom up, leaving the head to be the "main" diagnostic. | ||
* While it seems that DiagnosticMessageChain is structurally similar to DiagnosticMessage, | ||
* the difference is that messages are all preformatted in DMC. | ||
*/ | ||
``` | ||
|
||
The properties of a DMC are similar to a Diagnostic: | ||
|
||
```typescript | ||
const messageText = dmc.getMessageText(); // returns: string | ||
const category = dmc.getCategory(); // returns: ts.DiagnosticCategory | ||
const code = dmc.getCode(); // returns: number | ||
``` | ||
|
||
#### Next DMC in linked list | ||
|
||
Call `.getNext()`: | ||
|
||
```typescript | ||
const next = dmc.getNext(); // returns: DiagnosticMessageChain | undefined | ||
``` | ||
|
||
**Next step:** [Navigating the AST](../navigation/index) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export * from "./tools/LanguageService"; | ||
export * from "./tools/Diagnostic"; | ||
export * from "./tools/DiagnosticMessageChain"; | ||
export * from "./tools/LanguageService"; | ||
export * from "./tools/Program"; | ||
export * from "./tools/TypeChecker"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import * as ts from "typescript"; | ||
import {CompilerFactory} from "./../../factories"; | ||
import {SourceFile} from "./../file"; | ||
import {DiagnosticMessageChain} from "./DiagnosticMessageChain"; | ||
|
||
/** | ||
* Diagnostic. | ||
*/ | ||
export class Diagnostic { | ||
/** @internal */ | ||
readonly factory: CompilerFactory; | ||
/** @internal */ | ||
diagnostic: ts.Diagnostic; | ||
|
||
constructor( | ||
factory: CompilerFactory, | ||
diagnostic: ts.Diagnostic | ||
) { | ||
this.factory = factory; | ||
this.diagnostic = diagnostic; | ||
} | ||
|
||
/** | ||
* Gets the source file. | ||
*/ | ||
getSourceFile() { | ||
return this.factory.getSourceFile(this.diagnostic.file); | ||
} | ||
|
||
/** | ||
* Gets the message text. | ||
*/ | ||
getMessageText(): string | DiagnosticMessageChain { | ||
const messageText = this.diagnostic.messageText; | ||
if (typeof messageText === "string") | ||
return messageText; | ||
|
||
return this.factory.getDiagnosticMessageChain(messageText); | ||
} | ||
|
||
/** | ||
* Gets the start. | ||
*/ | ||
getStart() { | ||
return this.diagnostic.start; | ||
} | ||
|
||
/** | ||
* Gets the length. | ||
*/ | ||
getLength() { | ||
return this.diagnostic.length; | ||
} | ||
|
||
/** | ||
* Gets the diagnostic category. | ||
*/ | ||
getCategory(): ts.DiagnosticCategory { | ||
return this.diagnostic.category; | ||
} | ||
|
||
/** | ||
* Gets the code of the diagnostic. | ||
*/ | ||
getCode() { | ||
return this.diagnostic.code; | ||
} | ||
|
||
/** | ||
* Gets the source. | ||
*/ | ||
getSource() { | ||
return this.diagnostic.source; | ||
} | ||
|
||
/** | ||
* Gets the underlying compiler diagnostic. | ||
*/ | ||
getCompilerDiagnostic(): ts.Diagnostic { | ||
return this.diagnostic; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import * as ts from "typescript"; | ||
import {CompilerFactory} from "./../../factories"; | ||
|
||
/** | ||
* Diagnostic message chain. | ||
*/ | ||
export class DiagnosticMessageChain { | ||
/** @internal */ | ||
readonly factory: CompilerFactory; | ||
/** @internal */ | ||
diagnosticMessageChain: ts.DiagnosticMessageChain; | ||
|
||
constructor( | ||
factory: CompilerFactory, | ||
diagnosticMessageChain: ts.DiagnosticMessageChain | ||
) { | ||
this.factory = factory; | ||
this.diagnosticMessageChain = diagnosticMessageChain; | ||
} | ||
|
||
/** | ||
* Gets the message text. | ||
*/ | ||
getMessageText() { | ||
return this.diagnosticMessageChain.messageText; | ||
} | ||
|
||
/** | ||
* Gets th enext diagnostic message chain in the chain. | ||
*/ | ||
getNext(): DiagnosticMessageChain | undefined { | ||
const next = this.diagnosticMessageChain.next; | ||
if (next == null) | ||
return undefined; | ||
|
||
return this.factory.getDiagnosticMessageChain(next); | ||
} | ||
|
||
/** | ||
* Gets the code of the diagnostic message chain. | ||
*/ | ||
getCode() { | ||
return this.diagnosticMessageChain.code; | ||
} | ||
|
||
/** | ||
* Gets the category of the diagnostic message chain. | ||
*/ | ||
getCategory(): ts.DiagnosticCategory { | ||
return this.diagnosticMessageChain.category; | ||
} | ||
|
||
/** | ||
* Gets the underlying compiler object. | ||
*/ | ||
getCompilerDiagnosticMessageChain(): ts.DiagnosticMessageChain { | ||
return this.diagnosticMessageChain; | ||
} | ||
} |
Oops, something went wrong.