Skip to content

Commit

Permalink
Support generic types in datafields (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
Slava0135 authored Aug 29, 2024
1 parent 3e8b06a commit bf91eb1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/hover-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ export function registerHoverProvider() {
const datafield = parseDataFields(buf.toString()).find(it => it.name === datafieldName);
if (datafield) {
contents.pop();
contents.push(new vscode.MarkdownString(`**${datafield.type ?? wrapError('unknown type')}**`));
if (datafield.type) {
contents.push(new vscode.MarkdownString(`${codeBlock('csharp', datafield.type)}`));
} else {
contents.push(new vscode.MarkdownString(`**${wrapError('unknown type')}**`));
}
contents.push(new vscode.MarkdownString("---"));
const summary = parseDatafieldSummary(buf.toString(), datafieldName);
if (summary) {
contents.push(new vscode.MarkdownString(codeBlock('xml', summary)));
Expand Down
5 changes: 5 additions & 0 deletions src/parse/datafield.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ describe('parse datafields', () => {
assert.deepEqual(parseDataFields(source), expected);
});

it('one generic datafield', () => {
const source = readSource('one-generic-datafield');
assert.deepEqual(parseDataFields(source), [new DataField('guides', 'List<string>', 18)]);
});

});

function readSource(name: string): string {
Expand Down
4 changes: 1 addition & 3 deletions src/parse/datafield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ export class DataField {

constructor(name: string, type: string, line: number) {
this.name = name;
if (!type.includes(">") && !type.includes("<")) {
this.type = type;
}
this.type = type;
this.line = line;
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/parse/test-resources/datafield/one-generic-datafield.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;

namespace Content.Client.Guidebook.Components;

/// <summary>
/// This component stores a reference to a guidebook that contains information relevant to this entity.
/// </summary>
[RegisterComponent]
[Access(typeof(GuidebookSystem))]
public sealed partial class GuideHelpComponent : Component
{
/// <summary>
/// What guides to include show when opening the guidebook. The first entry will be used to select the currently
/// selected guidebook.
/// </summary>
[DataField("guides", customTypeSerializer: typeof(PrototypeIdListSerializer<GuideEntryPrototype>), required: true)]
[ViewVariables]
public List<string> Guides = new();
}

0 comments on commit bf91eb1

Please sign in to comment.