Skip to content

Commit 6fb3c56

Browse files
authored
Fix Variable Names (#71)
1 parent 5eaec42 commit 6fb3c56

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

client/src/services/context.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function isBeforeOrEqual(line1: number, col1: number, line2: number, col2: numbe
8888
}
8989

9090
export function filterInstanceVariables(variables: LJVariable[]): LJVariable[] {
91-
return variables.filter(v => !v.name.includes("#"));
91+
return variables.filter(v => !v.internalName.includes("#"));
9292
}
9393

9494
export function filterDuplicateVariables(variables: LJVariable[]): LJVariable[] {
@@ -104,20 +104,20 @@ export function filterDuplicateVariables(variables: LJVariable[]): LJVariable[]
104104
// Sorts variables by their position or name
105105
function sortVariables(variables: LJVariable[]): LJVariable[] {
106106
return variables.sort((left, right) => {
107-
if (!left.position && !right.position) return compareVariableNames(left, right);
107+
if (!left.position && !right.position) return compareVariableNames(left.internalName, right.internalName);
108108
if (!left.position) return 1;
109109
if (!right.position) return -1;
110110
if (left.position.lineStart !== right.position.lineStart) return left.position.lineStart - right.position.lineStart;
111111
if (left.position.colStart !== right.position.colStart) return right.position.colStart - left.position.colStart;
112-
return compareVariableNames(left, right);
112+
return compareVariableNames(left.internalName, right.internalName);
113113
});
114114
}
115115

116-
function compareVariableNames(a: LJVariable, b: LJVariable): number {
117-
if (a.name.startsWith("#") && b.name.startsWith("#")) return getOriginalVariableName(a.name).localeCompare(getOriginalVariableName(b.name));
118-
if (a.name.startsWith("#")) return 1;
119-
if (b.name.startsWith("#")) return -1;
120-
return a.name.localeCompare(b.name);
116+
function compareVariableNames(a: string, b: string): number {
117+
if (a.startsWith("#") && b.startsWith("#")) return getOriginalVariableName(a).localeCompare(getOriginalVariableName(b));
118+
if (a.startsWith("#")) return 1;
119+
if (b.startsWith("#")) return -1;
120+
return a.localeCompare(b);
121121
}
122122

123123
function normalizeVariableRefinements(variables: LJVariable[]): LJVariable[] {

client/src/types/context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { SourcePosition } from "./diagnostics";
44

55
export type LJVariable = {
66
name: string;
7+
internalName: string;
78
type: string;
89
refinement: string;
910
mainRefinement: string;

server/src/main/java/dtos/context/VariableDTO.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111
public record VariableDTO(
1212
String name,
13+
String internalName,
1314
String type,
1415
String refinement,
1516
String mainRefinement,
@@ -21,6 +22,7 @@ public static VariableDTO from(RefinedVariable refinedVariable) {
2122
if (placement == null) return null;
2223
return new VariableDTO(
2324
VariableFormatter.formatVariable(refinedVariable.getName()),
25+
refinedVariable.getName(),
2426
ContextHistoryDTO.stringifyType(refinedVariable.getType()),
2527
VariableFormatter.formatText(refinedVariable.getRefinement().toString()),
2628
VariableFormatter.formatText(refinedVariable.getMainRefinement().toString()),

0 commit comments

Comments
 (0)