Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Split return and param signatures into left/right, fixes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
damieng committed Aug 18, 2017
1 parent 6ca8002 commit 72c03ad
Showing 1 changed file with 47 additions and 5 deletions.
52 changes: 47 additions & 5 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,59 @@ class TypeScriptLanguageClient extends AutoLanguageClient {
return super.getSuggestions(request).then(results => {
if (results != null) {
for(const result of results) {
if (result.leftLabel) {
const index = result.leftLabel.lastIndexOf(':')
if (index > 0) {
result.leftLabel = result.leftLabel.substr(index + 1).trim()
}
if (result.leftLabel && result.displayText) {
this.setLeftAndRightFromParsedDisplayText(result)
}
}
}
return results
})
}

setLeftAndRightFromParsedDisplayText(result) {
const nameIndex = result.leftLabel.indexOf(result.displayText)
if (nameIndex >= 0) {
const signature = result.leftLabel.substr(nameIndex + result.displayText.length + 1).trim()
let paramsStart = -1
let paramsEnd = -1
let returnStart = -1
let bracesDepth = 0
for(let i = 0; i < signature.length; i++) {
switch(signature[i]) {
case '(': {
if (bracesDepth++ === 0 && paramsStart === -1) {
paramsStart = i;
}
break;
}
case ')': {
if (--bracesDepth === 0 && paramsEnd === -1) {
paramsEnd = i;
}
break;
}
case '>': {
if (returnStart === -1 && bracesDepth === 0 && i > 0 && signature[i-1] == '=') {
returnStart = i;
}
break;
}
case ':': {
if (returnStart === -1 && bracesDepth === 0) {
returnStart = i;
}
break;
}
}
}
if (paramsStart > -1) {
result.rightLabel = signature.substring(paramsStart, paramsEnd + 1).trim()
}
if (returnStart > -1) {
result.leftLabel = signature.substring(returnStart + 1).trim()
}
}
}
}

module.exports = new TypeScriptLanguageClient()

0 comments on commit 72c03ad

Please sign in to comment.