Skip to content

Commit

Permalink
don't use title as diagram name, #438, #400, #409
Browse files Browse the repository at this point in the history
  • Loading branch information
qjebbs committed Oct 12, 2021
1 parent 1099fba commit 040549f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 34 deletions.
51 changes: 27 additions & 24 deletions src/plantuml/diagram/diagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export class Diagram {
end: vscode.Position;
private _lines: string[] = undefined;
private _type: DiagramType = undefined;
private _titleRaw: string = undefined;
private _title: string = undefined;
private _nameRaw: string = undefined;
private _name: string = undefined;
private _index: number = undefined;
private _pageCount: number = undefined;
private _contentWithInclude: string = undefined;
Expand Down Expand Up @@ -70,13 +70,13 @@ export class Diagram {
public get type(): DiagramType {
return this._type || (this._type = getType(this));
}
public get title(): string {
if (this._title == undefined) this.getTitle()
return this._title
public get name(): string {
if (this._name == undefined) this.getTitle()
return this._name
}
public get titleRaw(): string {
if (this._title == undefined) this.getTitle()
return this._titleRaw
public get nameRaw(): string {
if (this._name == undefined) this.getTitle()
return this._nameRaw
}
public get lines(): string[] {
return this._lines || (this._lines = this.content.replace(/\r\n|\r/g, "\n").split('\n'));
Expand All @@ -96,28 +96,31 @@ export class Diagram {
let RegFName = /@start(\w+)\s+(.+?)\s*$/i;
let matches: RegExpMatchArray;;
if (matches = this.lines[0].match(RegFName)) {
this._titleRaw = matches[2];
this._title = title.Deal(this._titleRaw);
this._nameRaw = matches[2];
this._name = title.Deal(this._nameRaw);
return;
}
let inlineTitle = /^\s*title\s+(.+?)\s*$/i;
let multLineTitle = /^\s*title\s*$/i;
for (let text of this.lines) {
if (inlineTitle.test(text)) {
let matches = text.match(inlineTitle);
this._titleRaw = matches[1];
}
}
if (this._titleRaw) {
this._title = title.Deal(this._titleRaw);
} else if (this.start && this.end) {
// // don't use title as diagram name, #438, #400, #409
// let inlineTitle = /^\s*title\s+(.+?)\s*$/i;
// let multLineTitle = /^\s*title\s*$/i;
// for (let text of this.lines) {
// if (inlineTitle.test(text)) {
// let matches = text.match(inlineTitle);
// this._titleRaw = matches[1];
// }
// }
// if (this._titleRaw) {
// this._title = title.Deal(this._titleRaw);
// return
// }
if (this.start && this.end) {
// this.title = `${this.fileName}@${this.start.line + 1}-${this.end.line + 1}`;
if (this.index)
this._title = `${this.fileName}-${this.index}`;
this._name = `${this.fileName}-${this.index}`;
else
this._title = this.fileName;
this._name = this.fileName;
} else {
this._title = "";
this._name = "";
}
}
}
2 changes: 1 addition & 1 deletion src/plantuml/exporter/exportDiagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { config } from '../config';
export function exportDiagram(diagram: Diagram, format: string, savePath: string, bar: vscode.StatusBarItem): RenderTask {
if (bar) {
bar.show();
bar.text = localize(7, null, diagram.title + "." + format.split(":")[0]);
bar.text = localize(7, null, diagram.name + "." + format.split(":")[0]);
}
let renderTask = appliedRender(diagram.parentUri).render(diagram, format, savePath);
if (!config.exportMapFile(diagram.parentUri) || !savePath) return renderTask;
Expand Down
2 changes: 1 addition & 1 deletion src/plantuml/renders/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class LocalRender implements IRender {

let pms = processWrapper(process, savePath2).then(
stdout => buffers.push(stdout),
err => Promise.reject(<RenderError>{ error: localize(10, null, diagram.title, err.error), out: err.out })
err => Promise.reject(<RenderError>{ error: localize(10, null, diagram.name, err.error), out: err.out })
);
return pms;
},
Expand Down
2 changes: 1 addition & 1 deletion src/plantuml/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function calculateExportPath(diagram: Diagram, format: string): string {
if (config.exportSubFolder(diagram.parentUri)) {
exportDir = path.join(exportDir, diagram.fileName);
}
return path.join(exportDir, diagram.title + "." + format);
return path.join(exportDir, diagram.name + "." + format);
}
export function addFileIndex(fileName: string, index: number, count: number): string {
if (count == 1) return fileName;
Expand Down
4 changes: 2 additions & 2 deletions src/plantuml/urlMaker/urlMaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export function MakeDiagramsURL(diagrams: Diagram[], format: string, bar: vscode
export function MakeDiagramURL(diagram: Diagram, format: string, bar: vscode.StatusBarItem): DiagramURL {
if (bar) {
bar.show();
bar.text = localize(16, null, diagram.title);
bar.text = localize(16, null, diagram.name);
}
let server = config.server(diagram.parentUri);
return <DiagramURL>{
name: diagram.title,
name: diagram.name,
urls: [...Array(diagram.pageCount).keys()].map(index => makePlantumlURL(server, diagram, format, index))
}
}
8 changes: 4 additions & 4 deletions src/providers/diagnoser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class Diagnoser extends vscode.Disposable {
let names = {};
diagrams.map(d => {
let range = document.lineAt(d.start.line).range;
if (!d.titleRaw) {
if (!d.nameRaw) {
diagnostics.push(
new vscode.Diagnostic(
range,
Expand All @@ -42,16 +42,16 @@ export class Diagnoser extends vscode.Disposable {
)
);
}
if (names[d.title]) {
if (names[d.name]) {
diagnostics.push(
new vscode.Diagnostic(
range,
localize(31, null, d.title),
localize(31, null, d.name),
vscode.DiagnosticSeverity.Error
)
);
} else {
names[d.title] = true;
names[d.name] = true;
}
});
this.removeDiagnose(document);
Expand Down
2 changes: 1 addition & 1 deletion src/providers/symboler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class Symbol extends vscode.Disposable implements vscode.DocumentSymbolPr
const location = new vscode.Location(document.uri, new vscode.Range(d.start, d.end));
results.push(
new vscode.SymbolInformation(
d.title,
d.name,
vscode.SymbolKind.Object,
"",
location
Expand Down

0 comments on commit 040549f

Please sign in to comment.