Skip to content

Develop #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to the "bitloops-language" extension will be documented in t

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

### 0.4.4

Fixed bug of hover.

### 0.4.3

Fixed bug of hover for file not valid location.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ No known issues.

## What's New

### 0.4.3
### 0.4.4

Fixed bug of hover for file not valid location.
Fixed bug of hover.

---

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"icon": "assets/images/bitloops-language-logo-256x256.png",
"license": "MIT",
"version": "0.4.3",
"version": "0.4.4",
"scripts": {
"vs:package": "vsce package",
"vs:publish": "vsce publish",
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bitloops-lsp-server",
"description": "BitLoops Language Server",
"version": "0.4.3",
"version": "0.4.4",
"publisher": "Bitloops",
"license": "MIT",
"engines": {
Expand Down
55 changes: 31 additions & 24 deletions server/src/lsp/handlers/hover-handler/hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const handleHover = (
const document = TextDocument.create(params.textDocument.uri, 'bitloops', 1, fileContent);
const position = params.position;
const boundedContext = stateManager.getBoundedContext(params.textDocument.uri);

if (boundedContext === 'unknown') return null; //if the bounded context is unknown, we don't want to have hover provider
let word = findWord(document, position);
const symbolTable = analyzer.getSymbolTable() as TSymbolTableSemantics;
if (!symbolTable) return null;
Expand Down Expand Up @@ -49,32 +49,39 @@ const findWord = (document: TextDocument, position: Position): string => {
//for example: if the word is this.accountRepo.getById(accountId).ifError(), the array will contain the following elements:
//[this, this.accountRepo, this.accountRepo.getById(), accountId, this.accountRepo.getById().ifError()] in this order
for (const match of matches) {
if (match.includes('.')) {
const separateMatches = match.split('.');
let i = 1;
allMatches.push(separateMatches[0]);
while (i < separateMatches.length - 1) {
allMatches.push(allMatches[allMatches.length - 1] + '.' + separateMatches[i]);
i++;
try {
if (match.includes('.')) {
const separateMatches = match.split('.');
let i = 1;
allMatches.push(separateMatches[0]);
while (i < separateMatches.length - 1) {
allMatches.push(allMatches[allMatches.length - 1] + '.' + separateMatches[i]);
i++;
}
}
}
if (match === 'ifError(') allMatches.push(allMatches[allMatches.length - 2] + '.ifError()');
//special case for ifError: we want to concatenate with the previous method called, but without the variable in the parenthesis
else if (match.includes('(')) allMatches.push(match + ')');
//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
//because in the symbolTable it is stored as a method call, for example this.accountRepo.getById()
else allMatches.push(match);
if (match === 'ifError(') allMatches.push(allMatches[allMatches.length - 2] + '.ifError()');
//special case for ifError: we want to concatenate with the previous method called, but without the variable in the parenthesis
else if (match.includes('(')) allMatches.push(match + ')');
//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
//because in the symbolTable it is stored as a method call, for example this.accountRepo.getById()
else allMatches.push(match);
} catch (e) {}
}
for (let i = 0; i < allMatches.length; i++) {
let myLength = allMatches[i].length;
if (allMatches[i].includes('.')) {
myLength -= allMatches[i - 1].length;
} //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
if (currentPosition + myLength >= position.character && currentPosition <= position.character) {
return allMatches[i];
} else {
currentPosition += myLength + 1;
}
try {
let myLength = allMatches[i].length;
if (allMatches[i].includes('.')) {
myLength -= allMatches[i - 1].length;
} //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
if (
currentPosition + myLength >= position.character &&
currentPosition <= position.character
) {
return allMatches[i];
} else {
currentPosition += myLength + 1;
}
} catch (e) {}
}
return undefined;
};