Skip to content

Commit

Permalink
fix suggestions for block when typing already (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
carmenberndt committed Jun 17, 2020
1 parent 079d246 commit 48b9476
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions server/src/MessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,20 @@ export function handleCompletionRequest(
const lines = convertDocumentTextToTrimmedLineArray(document)
const currentLineUntrimmed = getCurrentLine(document, position.line)

const currentLineTillPosition = currentLineUntrimmed
.slice(0, position.character - 1)
.trim()
const wordsBeforePosition: string[] = currentLineTillPosition.split(/\s+/)

const symbolBeforePositionIsWhiteSpace =
getSymbolBeforePosition(document, position).search(/\s/) !== -1

const foundBlock = getBlockAtPosition(position.line, lines)
if (!foundBlock) {
if (!isFirstInLine(currentLineUntrimmed, position)) {
if (
wordsBeforePosition.length > 1 ||
(wordsBeforePosition.length === 1 && symbolBeforePositionIsWhiteSpace)
) {
return
}
return getSuggestionForBlockTypes(lines)
Expand All @@ -363,11 +374,6 @@ export function handleCompletionRequest(
)
}

const currentLineTillPosition = currentLineUntrimmed
.slice(0, position.character - 1)
.trim()
const wordsBeforePosition: string[] = currentLineTillPosition.split(/\s+/)

// Completion was triggered by a triggerCharacter
if (context.triggerKind === 2) {
switch (context.triggerCharacter) {
Expand All @@ -394,9 +400,6 @@ export function handleCompletionRequest(
}
}

const symbolBeforePositionIsWhiteSpace =
getSymbolBeforePosition(document, position).search(/\s/) !== -1

switch (foundBlock.type) {
case 'model':
// check if inside attribute
Expand Down

0 comments on commit 48b9476

Please sign in to comment.