Skip to content

Commit 6ece4cc

Browse files
authored
Develop (#29)
* fixed bugs of hover
1 parent 3bf5e55 commit 6ece4cc

File tree

5 files changed

+39
-28
lines changed

5 files changed

+39
-28
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to the "bitloops-language" extension will be documented in t
44

55
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
66

7+
### 0.4.4
8+
9+
Fixed bug of hover.
10+
711
### 0.4.3
812

913
Fixed bug of hover for file not valid location.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ No known issues.
3333

3434
## What's New
3535

36-
### 0.4.3
36+
### 0.4.4
3737

38-
Fixed bug of hover for file not valid location.
38+
Fixed bug of hover.
3939

4040
---
4141

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"icon": "assets/images/bitloops-language-logo-256x256.png",
1111
"license": "MIT",
12-
"version": "0.4.3",
12+
"version": "0.4.4",
1313
"scripts": {
1414
"vs:package": "vsce package",
1515
"vs:publish": "vsce publish",

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "bitloops-lsp-server",
33
"description": "BitLoops Language Server",
4-
"version": "0.4.3",
4+
"version": "0.4.4",
55
"publisher": "Bitloops",
66
"license": "MIT",
77
"engines": {

server/src/lsp/handlers/hover-handler/hover.ts

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const handleHover = (
1313
const document = TextDocument.create(params.textDocument.uri, 'bitloops', 1, fileContent);
1414
const position = params.position;
1515
const boundedContext = stateManager.getBoundedContext(params.textDocument.uri);
16-
16+
if (boundedContext === 'unknown') return null; //if the bounded context is unknown, we don't want to have hover provider
1717
let word = findWord(document, position);
1818
const symbolTable = analyzer.getSymbolTable() as TSymbolTableSemantics;
1919
if (!symbolTable) return null;
@@ -49,32 +49,39 @@ const findWord = (document: TextDocument, position: Position): string => {
4949
//for example: if the word is this.accountRepo.getById(accountId).ifError(), the array will contain the following elements:
5050
//[this, this.accountRepo, this.accountRepo.getById(), accountId, this.accountRepo.getById().ifError()] in this order
5151
for (const match of matches) {
52-
if (match.includes('.')) {
53-
const separateMatches = match.split('.');
54-
let i = 1;
55-
allMatches.push(separateMatches[0]);
56-
while (i < separateMatches.length - 1) {
57-
allMatches.push(allMatches[allMatches.length - 1] + '.' + separateMatches[i]);
58-
i++;
52+
try {
53+
if (match.includes('.')) {
54+
const separateMatches = match.split('.');
55+
let i = 1;
56+
allMatches.push(separateMatches[0]);
57+
while (i < separateMatches.length - 1) {
58+
allMatches.push(allMatches[allMatches.length - 1] + '.' + separateMatches[i]);
59+
i++;
60+
}
5961
}
60-
}
61-
if (match === 'ifError(') allMatches.push(allMatches[allMatches.length - 2] + '.ifError()');
62-
//special case for ifError: we want to concatenate with the previous method called, but without the variable in the parenthesis
63-
else if (match.includes('(')) allMatches.push(match + ')');
64-
//for methods: we keep the opening parenthesis in the matched word so we can separate the method from the variable and then we add the closing parenthesis
65-
//because in the symbolTable it is stored as a method call, for example this.accountRepo.getById()
66-
else allMatches.push(match);
62+
if (match === 'ifError(') allMatches.push(allMatches[allMatches.length - 2] + '.ifError()');
63+
//special case for ifError: we want to concatenate with the previous method called, but without the variable in the parenthesis
64+
else if (match.includes('(')) allMatches.push(match + ')');
65+
//for methods: we keep the opening parenthesis in the matched word so we can separate the method from the variable and then we add the closing parenthesis
66+
//because in the symbolTable it is stored as a method call, for example this.accountRepo.getById()
67+
else allMatches.push(match);
68+
} catch (e) {}
6769
}
6870
for (let i = 0; i < allMatches.length; i++) {
69-
let myLength = allMatches[i].length;
70-
if (allMatches[i].includes('.')) {
71-
myLength -= allMatches[i - 1].length;
72-
} //if the word contains a dot, we subtract the length of the previous word from the length of the current word, as we keep the dot member in the previous word
73-
if (currentPosition + myLength >= position.character && currentPosition <= position.character) {
74-
return allMatches[i];
75-
} else {
76-
currentPosition += myLength + 1;
77-
}
71+
try {
72+
let myLength = allMatches[i].length;
73+
if (allMatches[i].includes('.')) {
74+
myLength -= allMatches[i - 1].length;
75+
} //if the word contains a dot, we subtract the length of the previous word from the length of the current word, as we keep the dot member in the previous word
76+
if (
77+
currentPosition + myLength >= position.character &&
78+
currentPosition <= position.character
79+
) {
80+
return allMatches[i];
81+
} else {
82+
currentPosition += myLength + 1;
83+
}
84+
} catch (e) {}
7885
}
7986
return undefined;
8087
};

0 commit comments

Comments
 (0)