-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: i18n of issues #70
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
72c2594
Issues I18n #69
alessiostalla 212b016
#69 Store parameters as object rather than array.
alessiostalla f0acb6c
#69 Change issue args format again so that it's friendly to both inde…
alessiostalla 4d4067d
#69 More thorough Issue tests in ECore
alessiostalla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,31 +1,43 @@ | ||
import {Node} from "./model/model"; | ||
import {Position} from "./model/position"; | ||
|
||
export enum IssueType { LEXICAL, SYNTACTIC, SEMANTIC} | ||
|
||
export enum IssueSeverity { ERROR, WARNING, INFO} | ||
|
||
export interface IssueArg { | ||
name: string; | ||
value: string; | ||
} | ||
|
||
export class Issue { | ||
type: IssueType; | ||
message: string; | ||
severity: IssueSeverity = IssueSeverity.ERROR; | ||
position?: Position; | ||
|
||
constructor(type: IssueType, message: string, severity: IssueSeverity, position?: Position) { | ||
this.type = type; | ||
this.message = message; | ||
this.severity = severity; | ||
this.position = position; | ||
|
||
constructor( | ||
public readonly type: IssueType, | ||
public readonly message: string, | ||
public readonly severity: IssueSeverity, | ||
public readonly position?: Position, | ||
public readonly node?: Node, | ||
public readonly code?: string, | ||
public readonly args: IssueArg[] = [] | ||
) { | ||
if (!position) { | ||
this.position = node?.position; | ||
} | ||
} | ||
|
||
static lexical(message: string, severity: IssueSeverity = IssueSeverity.ERROR, position?: Position): Issue { | ||
return new Issue(IssueType.LEXICAL, message, severity, position); | ||
static lexical(message: string, severity: IssueSeverity = IssueSeverity.ERROR, position?: Position, | ||
node?: Node, code?: string, args: IssueArg[] = []): Issue { | ||
return new Issue(IssueType.LEXICAL, message, severity, position, node, code, args); | ||
} | ||
|
||
static syntactic(message: string, severity: IssueSeverity = IssueSeverity.ERROR, position?: Position): Issue { | ||
return new Issue(IssueType.SYNTACTIC, message, severity, position); | ||
static syntactic(message: string, severity: IssueSeverity = IssueSeverity.ERROR, position?: Position, | ||
node?: Node, code?: string, args: IssueArg[] = []): Issue { | ||
return new Issue(IssueType.SYNTACTIC, message, severity, position, node, code, args); | ||
} | ||
|
||
static semantic(message: string, severity: IssueSeverity = IssueSeverity.ERROR, position?: Position): Issue { | ||
return new Issue(IssueType.SEMANTIC, message, severity, position); | ||
static semantic(message: string, severity: IssueSeverity = IssueSeverity.ERROR, position?: Position, | ||
node?: Node, code?: string, args: IssueArg[] = []): Issue { | ||
return new Issue(IssueType.SEMANTIC, message, severity, position, node, code, args); | ||
} | ||
} | ||
} |
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,33 @@ | ||
import {Issue, IssueSeverity, SOURCE_NODE_NOT_MAPPED} from "../src"; | ||
import i18next from 'i18next'; | ||
import {SYNTAX_ERROR} from "../src/parsing"; | ||
import {expect} from "chai"; | ||
|
||
describe('Issues', function() { | ||
it("can be translated", | ||
function () { | ||
i18next.init({ | ||
lng: 'en', // if you're using a language detector, do not define the lng option | ||
debug: true, | ||
resources: { | ||
en: { | ||
translation: { | ||
ast: { | ||
transform: { | ||
sourceNotMapped: "Source node not mapped: {{type}}" | ||
} | ||
}, | ||
parser: { | ||
syntaxError: "A syntax error occurred!" | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
let issue = Issue.syntactic("Unexpected token: foo", IssueSeverity.ERROR, undefined, undefined, SYNTAX_ERROR); | ||
expect(i18next.t(issue.code!)).to.equal("A syntax error occurred!"); | ||
issue = Issue.semantic("Node not mapped: SomeNode", IssueSeverity.ERROR, undefined, undefined, | ||
SOURCE_NODE_NOT_MAPPED, [{ name: "nodeType", value: "SomeNode" }]); | ||
expect(i18next.t(issue.code!, { type: issue.args[0].value })).to.equal("Source node not mapped: SomeNode"); | ||
}); | ||
}); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should bump the version of the metamodel for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, this is only needed because for some reason in the Ecore compatibility layer we decide that something is an issue if it has the same features as the Issue EClass. Since we're going to abandon ECore anyway, I wouldn't spend much on it.