Skip to content

Commit

Permalink
Add duplicate keys warning
Browse files Browse the repository at this point in the history
  • Loading branch information
cooolbros committed Dec 21, 2024
1 parent e0ab83d commit 166cc0b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/server/src/VDF/VDFLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export abstract class VDFLanguageServer<
// @ts-ignore
return [
...(value.reference ? value.reference.flatMap(include) : []),
...value.values.filter((value) => (text ? value.label.toLowerCase().startsWith(text.toLowerCase()) : true) && (value.multiple ? true : !documentSymbol.children?.some((d) => d.key.toLowerCase() == value.label.toLowerCase())))
...value.values?.filter((value) => (text ? value.label.toLowerCase().startsWith(text.toLowerCase()) : true) && (value.multiple ? true : !documentSymbol.children?.some((d) => d.key.toLowerCase() == value.label.toLowerCase()))) ?? []
]
}

Expand Down
37 changes: 36 additions & 1 deletion packages/server/src/VDF/VDFTextDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export interface VDFTextDocumentDependencies {
}

export interface VDFTextDocumentSchema {
keys: Record<string, { reference?: string[], values: { label: string, kind: number, multiple?: boolean }[] }>
keys: Record<string, { distinct?: boolean, reference?: string[], values?: { label: string, kind: number, multiple?: boolean }[] }>
values: Record<string, { kind: number, enumIndex?: boolean, values: string[], fix?: Record<string, string> }>
definitionReferences: {
type: symbol
Expand Down Expand Up @@ -386,6 +386,41 @@ export abstract class VDFTextDocument<TDocument extends VDFTextDocument<TDocumen
const documentSymbolKey = configuration.keyTransform(documentSymbol.key.toLowerCase())
const documentSymbolValue = documentSymbol.detail.toLowerCase()

// Distinct Keys
if (documentSymbolKey in dependencies.schema.keys && dependencies.schema.keys[documentSymbolKey].distinct == true) {
const parent = path.at(-1)
if (parent?.children != undefined) {
const first = parent.children.find((i) => configuration.keyTransform(i.key.toLowerCase()) == documentSymbolKey && i.conditional?.toLowerCase() == documentSymbol.conditional?.toLowerCase())!
if (first != documentSymbol) {
diagnostics.push({
range: documentSymbol.nameRange,
severity: DiagnosticSeverity.Warning,
code: "duplicate-key",
source: init.languageId,
message: `Duplicate ${first.key}`,
relatedInformation: [
{
location: {
uri: this.uri.toString(),
range: first.nameRange
},
message: `${first.key} is declared here.`
}
],
data: {
kind: CodeActionKind.QuickFix,
fix: (createDocumentWorkspaceEdit) => {
return {
title: `Remove duplicate ${documentSymbol.key}`,
edit: createDocumentWorkspaceEdit(documentSymbol.range, "")
}
}
}
})
}
}
}

// Static
if (documentSymbolKey in dependencies.schema.values) {
const valueData = dependencies.schema.values[documentSymbolKey]
Expand Down
33 changes: 33 additions & 0 deletions packages/server/src/VDF/VGUI/keys.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"autoresize": {
"distinct": true
},
"button": {
"reference": [
"cexlabel"
Expand Down Expand Up @@ -48,6 +51,9 @@
}
]
},
"controlname": {
"distinct": true
},
"ctfimagepanel": {
"reference": [
"imagepanel"
Expand Down Expand Up @@ -82,6 +88,12 @@
}
]
},
"enabled": {
"distinct": true
},
"fieldname": {
"distinct": true
},
"imagepanel": {
"reference": [
"panel"
Expand Down Expand Up @@ -263,5 +275,26 @@
"kind": 5
}
]
},
"pincorner": {
"distinct": true
},
"tall": {
"distinct": true
},
"visible": {
"distinct": true
},
"wide": {
"distinct": true
},
"xpos": {
"distinct": true
},
"ypos": {
"distinct": true
},
"zpos": {
"distinct": true
}
}

0 comments on commit 166cc0b

Please sign in to comment.