Skip to content

Commit 7c4425c

Browse files
authored
Added fileId to the scope of keyword (#470)
- Bug fix for the language server
1 parent 1877d0d commit 7c4425c

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

transpiler/__tests__/end-to-end/mocks/symbol-table/symbol-table.ts

+17-10
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,14 @@ export const SYMBOL_TABLE_FIND_TYPE_OF_KEYWORD_TEST_CASES = [
10961096
inputSetup: FileUtil.readFileString(
10971097
'transpiler/__tests__/end-to-end/mocks/semantic-errors/setup.bl',
10981098
),
1099-
keywordInfo: { name: 'accountEntity', position: { line: 16, column: 22 } },
1099+
keywordInfo: {
1100+
name: 'accountEntity',
1101+
position: {
1102+
line: 16,
1103+
column: 22,
1104+
fileId: 'fileId',
1105+
},
1106+
},
11001107
expectedOutput: { type: '(OK(AccountEntity), Errors(UnexpectedError))', isConst: true },
11011108
},
11021109
{
@@ -1107,7 +1114,7 @@ export const SYMBOL_TABLE_FIND_TYPE_OF_KEYWORD_TEST_CASES = [
11071114
inputSetup: FileUtil.readFileString(
11081115
'transpiler/__tests__/end-to-end/mocks/semantic-errors/setup.bl',
11091116
),
1110-
keywordInfo: { name: 'accountEntity', position: { line: 16, column: 22 } },
1117+
keywordInfo: { name: 'accountEntity', position: { line: 16, column: 22, fileId: 'fileId' } },
11111118
expectedOutput: { type: 'AccountEntity', isConst: true },
11121119
},
11131120
{
@@ -1118,7 +1125,7 @@ export const SYMBOL_TABLE_FIND_TYPE_OF_KEYWORD_TEST_CASES = [
11181125
inputSetup: FileUtil.readFileString(
11191126
'transpiler/__tests__/end-to-end/mocks/semantic-errors/setup.bl',
11201127
),
1121-
keywordInfo: { name: 'result', position: { line: 17, column: 22 } },
1128+
keywordInfo: { name: 'result', position: { line: 17, column: 22, fileId: 'fileId' } },
11221129
expectedOutput: { type: 'string', isConst: true },
11231130
},
11241131
{
@@ -1129,7 +1136,7 @@ export const SYMBOL_TABLE_FIND_TYPE_OF_KEYWORD_TEST_CASES = [
11291136
inputSetup: FileUtil.readFileString(
11301137
'transpiler/__tests__/end-to-end/mocks/semantic-errors/setup.bl',
11311138
),
1132-
keywordInfo: { name: 'message', position: { line: 23, column: 23 } },
1139+
keywordInfo: { name: 'message', position: { line: 23, column: 23, fileId: 'fileId' } },
11331140
expectedOutput: { type: 'string', isConst: true },
11341141
},
11351142
{
@@ -1140,7 +1147,7 @@ export const SYMBOL_TABLE_FIND_TYPE_OF_KEYWORD_TEST_CASES = [
11401147
inputSetup: FileUtil.readFileString(
11411148
'transpiler/__tests__/end-to-end/mocks/semantic-errors/setup.bl',
11421149
),
1143-
keywordInfo: { name: 'account', position: { line: 17, column: 24 } },
1150+
keywordInfo: { name: 'account', position: { line: 17, column: 24, fileId: 'fileId' } },
11441151
expectedOutput: { type: '(OK(AccountReadModel), Errors(UnexpectedError))', isConst: true },
11451152
},
11461153
{
@@ -1151,7 +1158,7 @@ export const SYMBOL_TABLE_FIND_TYPE_OF_KEYWORD_TEST_CASES = [
11511158
inputSetup: FileUtil.readFileString(
11521159
'transpiler/__tests__/end-to-end/mocks/semantic-errors/setup.bl',
11531160
),
1154-
keywordInfo: { name: 'animal', position: { line: 22, column: 19 } },
1161+
keywordInfo: { name: 'animal', position: { line: 22, column: 19, fileId: 'fileId' } },
11551162
expectedOutput: { type: 'string', isConst: true },
11561163
},
11571164
{
@@ -1162,7 +1169,7 @@ export const SYMBOL_TABLE_FIND_TYPE_OF_KEYWORD_TEST_CASES = [
11621169
inputSetup: FileUtil.readFileString(
11631170
'transpiler/__tests__/end-to-end/mocks/semantic-errors/setup.bl',
11641171
),
1165-
keywordInfo: { name: 'bird', position: { line: 43, column: 20 } },
1172+
keywordInfo: { name: 'bird', position: { line: 43, column: 20, fileId: 'fileId' } },
11661173
expectedOutput: { type: 'string', isConst: true },
11671174
},
11681175
{
@@ -1173,7 +1180,7 @@ export const SYMBOL_TABLE_FIND_TYPE_OF_KEYWORD_TEST_CASES = [
11731180
inputSetup: FileUtil.readFileString(
11741181
'transpiler/__tests__/end-to-end/mocks/semantic-errors/setup.bl',
11751182
),
1176-
keywordInfo: { name: 'cat', position: { line: 49, column: 26 } },
1183+
keywordInfo: { name: 'cat', position: { line: 49, column: 26, fileId: 'fileId' } },
11771184
expectedOutput: { type: 'string', isConst: true },
11781185
},
11791186
{
@@ -1184,7 +1191,7 @@ export const SYMBOL_TABLE_FIND_TYPE_OF_KEYWORD_TEST_CASES = [
11841191
inputSetup: FileUtil.readFileString(
11851192
'transpiler/__tests__/end-to-end/mocks/semantic-errors/setup.bl',
11861193
),
1187-
keywordInfo: { name: 'isNew', position: { line: 20, column: 16 } },
1194+
keywordInfo: { name: 'isNew', position: { line: 20, column: 16, fileId: 'fileId' } },
11881195
expectedOutput: { type: 'bool', isConst: true },
11891196
},
11901197
{
@@ -1195,7 +1202,7 @@ export const SYMBOL_TABLE_FIND_TYPE_OF_KEYWORD_TEST_CASES = [
11951202
inputSetup: FileUtil.readFileString(
11961203
'transpiler/__tests__/end-to-end/mocks/semantic-errors/setup.bl',
11971204
),
1198-
keywordInfo: { name: 'command', position: { line: 9, column: 36 } },
1205+
keywordInfo: { name: 'command', position: { line: 9, column: 36, fileId: 'fileId' } },
11991206
expectedOutput: { type: 'SendEmailCommand', isConst: true },
12001207
},
12011208
];

transpiler/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bitloops/bl-transpiler",
3-
"version": "0.6.9",
3+
"version": "0.6.10",
44
"description": "The one and only Bitloops Language transpiler",
55
"engines": {
66
"node": ">= 13"

transpiler/src/semantic-analysis/type-inference/SymbolTable.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -109,25 +109,30 @@ export class SymbolTable {
109109
public findScopeOfKeyword({
110110
line,
111111
column,
112+
fileId,
112113
}: {
113114
line: number;
114115
column: number;
116+
fileId: string;
115117
}): IntermediateASTNode[] | null {
116-
const nodes = this.findScopeByPosition(undefined, { line, column });
118+
const nodes = this.findScopeByPosition(undefined, { line, column, fileId });
117119
return nodes;
118120
}
119121
private findScopeByPosition(
120122
nodes: IntermediateASTNode[] = [],
121123
{
122124
line,
123125
column,
126+
fileId,
124127
}: {
125128
line: number;
126129
column: number;
130+
fileId: string;
127131
},
128132
): IntermediateASTNode[] | null {
129133
if (
130134
this.node &&
135+
this.node.getMetadata().fileId === fileId &&
131136
this.node.getMetadata()?.start.line <= line &&
132137
this.node.getMetadata()?.start.column <= column &&
133138
this.node.getMetadata()?.end.line >= line
@@ -136,7 +141,7 @@ export class SymbolTable {
136141
nodes.push(this.node);
137142
}
138143
for (const child of Object.values(this.childrenScopes)) {
139-
child.findScopeByPosition(nodes, { line, column });
144+
child.findScopeByPosition(nodes, { line, column, fileId });
140145
}
141146
if (nodes.length === 0) {
142147
return null;
@@ -147,12 +152,12 @@ export class SymbolTable {
147152
//returns the type of the keyword and if it is const or not
148153
public findTypeOfKeyword(
149154
keyword: string,
150-
{ line, column }: { line: number; column: number },
155+
{ line, column, fileId }: { line: number; column: number; fileId: string },
151156
): {
152157
type: string | null;
153158
isConst: boolean | null;
154159
} {
155-
const nodes = this.findScopeOfKeyword({ line, column });
160+
const nodes = this.findScopeOfKeyword({ line, column, fileId });
156161
let type;
157162
let isConst;
158163
let childScopes: SymbolTable;

0 commit comments

Comments
 (0)