|
5 | 5 | 'use strict'; |
6 | 6 |
|
7 | 7 | import {sequence} from 'vs/base/common/async'; |
8 | | -import {IModel, IPosition} from 'vs/editor/common/editorCommon'; |
| 8 | +import {IModel, IPosition, IRange} from 'vs/editor/common/editorCommon'; |
9 | 9 | import {TPromise} from 'vs/base/common/winjs.base'; |
10 | 10 | import {mixin} from 'vs/base/common/objects'; |
11 | 11 | import {onUnexpectedError, illegalArgument} from 'vs/base/common/errors'; |
@@ -42,29 +42,52 @@ export function suggest(model: IModel, position: IPosition, triggerCharacter: st |
42 | 42 |
|
43 | 43 | // for each support in the group ask for suggestions |
44 | 44 | let promises = supports.map(support => { |
45 | | - return support.suggest(resource, position, triggerCharacter).then(value => { |
| 45 | + return support.suggest(resource, position, triggerCharacter).then(values => { |
46 | 46 |
|
47 | 47 | let result: ISuggestions2[] = []; |
48 | | - for (let suggestions of value) { |
| 48 | + for (let suggestResult of values) { |
49 | 49 |
|
50 | | - if (!suggestions |
51 | | - || !Array.isArray(suggestions.suggestions) |
52 | | - || suggestions.suggestions.length === 0) { |
| 50 | + if (!suggestResult |
| 51 | + || !Array.isArray(suggestResult.suggestions) |
| 52 | + || suggestResult.suggestions.length === 0) { |
53 | 53 |
|
54 | 54 | continue; |
55 | 55 | } |
56 | 56 |
|
57 | 57 | const suggestions2: ISuggestions2 = { |
58 | 58 | support, |
59 | | - currentWord: suggestions.currentWord, |
60 | | - incomplete: suggestions.incomplete, |
61 | | - overwriteAfter: suggestions.overwriteAfter, |
62 | | - overwriteBefore: suggestions.overwriteBefore, |
63 | | - suggestions: suggestions.suggestions |
| 59 | + currentWord: suggestResult.currentWord, |
| 60 | + incomplete: suggestResult.incomplete, |
| 61 | + overwriteAfter: suggestResult.overwriteAfter, |
| 62 | + overwriteBefore: suggestResult.overwriteBefore, |
| 63 | + suggestions: suggestResult.suggestions |
| 64 | + } |
| 65 | + |
| 66 | + const defaultRange: IRange = { |
| 67 | + startLineNumber: position.lineNumber, |
| 68 | + startColumn: position.column, |
| 69 | + endLineNumber: position.lineNumber, |
| 70 | + endColumn: position.column |
| 71 | + }; |
| 72 | + |
| 73 | + if (typeof suggestResult.overwriteBefore === 'number' && suggestResult.overwriteBefore > 0) { |
| 74 | + defaultRange.startColumn -= suggestResult.overwriteBefore; |
| 75 | + } |
| 76 | + if (typeof suggestResult.overwriteAfter === 'number' && suggestResult.overwriteAfter > 0) { |
| 77 | + defaultRange.endColumn += suggestResult.overwriteAfter |
| 78 | + } |
| 79 | + |
| 80 | + for (let suggestion of suggestResult.suggestions) { |
| 81 | + if (!suggestion.textEdit) { |
| 82 | + suggestion.textEdit = { |
| 83 | + text: suggestion.codeSnippet, |
| 84 | + range: defaultRange |
| 85 | + }; |
| 86 | + } |
64 | 87 | } |
65 | 88 |
|
66 | 89 | // add additional properties |
67 | | - mixin(suggestions2, suggestions, false); |
| 90 | + mixin(suggestions2, suggestResult, false); |
68 | 91 | result.push(suggestions2); |
69 | 92 | } |
70 | 93 |
|
|
0 commit comments