Skip to content

Commit

Permalink
Merge branch 'master' into feature/labels-completion
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Feb 3, 2021
2 parents 3b38321 + 2cb5934 commit e13a88d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/LanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ export class LanguageServer {
);

const activeSignature = signatures.length > 0 ? 0 : null;
const activeParameter = activeSignature >= 0 ? signatures[activeSignature].index : null;
const activeParameter = activeSignature >= 0 ? signatures[activeSignature]?.index : null;
let results: SignatureHelp = {
signatures: signatures.map((s) => s.signature),
activeSignature: activeSignature,
Expand Down
13 changes: 13 additions & 0 deletions src/Program.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,19 @@ describe('Program', () => {
});

describe('getSignatureHelp', () => {
it('ignores comments and invalid ranges', () => {
program.addOrReplaceFile('source/main.bs', `
function main()
' new func(((
end function
`);
for (let col = 0; col < 40; col++) {
let signatureHelp = (program.getSignatureHelp(`${rootDir}/source/main.bs`, Position.create(2, col)));
expect(program.getDiagnostics()).to.be.empty;
expect(signatureHelp[0]?.signature).to.not.exist;
}
});

it('gets signature help for constructor with no args', () => {
program.addOrReplaceFile('source/main.bs', `
function main()
Expand Down
35 changes: 23 additions & 12 deletions src/Program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ export class Program {
let functionScope = file.getFunctionScopeAtPosition(position);
let identifierInfo = this.getPartialStatementInfo(file, position);
if (identifierInfo.statementType === '') {
// just general functoin calls
// just general function calls
let statements = file.program.getStatementsByName(identifierInfo.name, file);
for (let statement of statements) {
//TODO better handling of collisions - if it's a namespace, then don't show any other overrides
Expand Down Expand Up @@ -839,19 +839,25 @@ export class Program {
//try to get sig help based on the name
index = position.character;
let currentToken = file.getTokenAt(position);
name = file.getPartialVariableName(currentToken, [TokenKind.New]);
if (!name) {
//try the previous token, incase we're on a bracket
currentToken = file.getPreviousToken(currentToken);
if (currentToken && currentToken.kind !== TokenKind.Comment) {
name = file.getPartialVariableName(currentToken, [TokenKind.New]);
}
if (name?.indexOf('.')) {
let parts = name.split('.');
name = parts[parts.length - 1];
}
if (!name) {
//try the previous token, incase we're on a bracket
currentToken = file.getPreviousToken(currentToken);
name = file.getPartialVariableName(currentToken, [TokenKind.New]);
}
if (name?.indexOf('.')) {
let parts = name.split('.');
name = parts[parts.length - 1];
}

index = currentToken.range.start.character;
argStartIndex = index;
index = currentToken.range.start.character;
argStartIndex = index;
} else {
// invalid location
index = 0;
itemCounts.comma = 0;
}
}
while (index > 0) {
if (!(/[a-z0-9_\.\@]/i).test(line.charAt(index))) {
Expand Down Expand Up @@ -903,6 +909,11 @@ export class Program {
while (index >= 0) {
const currentChar = line.charAt(index);

if (currentChar === '\'') { //found comment, invalid index
itemCounts.isArgStartFound = false;
break;
}

if (isArgStartFound) {
if (currentChar !== ' ') {
break;
Expand Down

0 comments on commit e13a88d

Please sign in to comment.