mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-21 12:20:29 -04:00
Merge VS Code 1.26.1 (#2394)
* Squash merge commits for 1.26 (#1) (#2323) * Polish tag search as per feedback (#55269) * Polish tag search as per feedback * Updated regex * Allow users to opt-out of features that send online requests in the background (#55097) * settings sweep #54690 * Minor css tweaks to enable eoverflow elipsis in more places (#55277) * fix an issue with titlebarheight when not scaling with zoom * Settings descriptions update #54690 * fixes #55209 * Settings editor - many padding fixes * More space above level 2 label * Fixing Cannot debug npm script using Yarn #55103 * Settings editor - show ellipsis when description overflows * Settings editor - ... fix measuring around links, relayout * Setting descriptions * Settings editor - fix ... for some short lines, fix select container width * Settings editor - overlay trees so scrollable shadow is full width * Fix #54133 - missing extension settings after reload * Settings color token description tweak * Settings editor - disable overflow indicator temporarily, needs to be faster * Added command to Run the selected npm script * fixes #54452 * fixes #54929 * fixes #55248 * prefix command with extension name * Contribute run selected to the context menu * node-debug@1.26.6 * Allow terminal rendererType to be swapped out at runtime Part of #53274 Fixes #55344 * Settings editor - fix not focusing search when restoring editor setInput must be actually async. Will be fixed naturally when we aren't using winJS promises... * Settings editor - TOC should only expand the section with a selected item * Bump node-debug2 * Settings editor - Tree focus outlines * Settings editor - don't blink the scrollbar when toc selection changes And hide TOC correctly when the editor is narrow * Settings editor - header rows should not be selectable * fixes #54877 * change debug assignee to isi * Settings sweep (#54690) * workaround for #55051 * Settings sweep (#54690) * settings sweep #54690 * Don't try closing tags when you type > after another > * Describe what implementation code lens does Fixes #55370 * fix javadoc formatter setting description * fixes #55325 * update to officical TS version * Settings editor - Even more padding, use semibold instead of bold * Fix #55357 - fix TOC twistie * fixes #55288 * explorer: refresh on di change file system provider registration fixes #53256 * Disable push to Linux repo to test standalone publisher * New env var to notify log level to extensions #54001 * Disable snippets in extension search (when not in suggest dropdown) (#55281) * Disable snippits in extension search (when not in suggest dropdown) * Add monaco input contributions * Fix bug preventing snippetSuggestions from taking effect in sub-editors * Latest emmet helper to fix #52366 * Fix comment updates for threads within same file * Allow extensions to log telemetry to log files #54001 * Pull latest css grammar * files.exclude control - use same style for "add" vs "edit" * files.exclude control - focus/keyboard behavior * don't show menubar too early * files.exclude - better styling * Place cursor at end of extensions search box on autofill (#55254) * Place cursor at end of extensions search box on autofill * Use position instead of selection * fix linux build issue (empty if block) * Settings editor - fix extension category prefixes * Settings editor - add simple ellipsis for first line that overflows, doesn't cover case when first line does not overflow but there is more text, TODO * File/Text search provider docs * Fixes #52655 * Include epoch (#55008) * Fixes #53385 * Fixes #49480 * VS Code Insiders (Users) not opening Fixes #55353 * Better handling of the case when the extension host fails to start * Fixes #53966 * Remove confusing Start from wordPartLeft commands ID * vscode-xterm@3.6.0-beta12 Fixes #55488 * Initial size is set to infinity!! Fixes #55461 * Polish embeddedEditorBackground * configuration service misses event * Fix #55224 - fix duplicate results in multiroot workspace from splitting the diskseach query * Select all not working in issue reporter on mac, fixes #55424 * Disable fuzzy matching for extensions autosuggest (#55498) * Fix clipping of extensions search border in some third party themes (#55504) * fixes #55538 * Fix bug causing an aria alert to not be shown the third time (and odd numbers thereafter) * Settings editor - work around rendering glitch with webkit-line-clamp * Settings editor - revert earlier '...' changes * Settings editor - move enumDescription to its own div, because it disturbs -webkit-line-clamp for some reason * Settings editor - better overflow indicator * Don't show existing filters in autocomplete (#55495) * Dont show existing filters in autocomplete * Simplify * Settings Editor: Add aria labels for input elements Fixes: #54836 (#55543) * fixes #55223 * Update vscode-css-languageservice to 3.0.10-next.1 * Fix #55509 - settings navigation * Fix #55519 * Fix #55520 * FIx #55524 * Fix #55556 - include wordSeparators in all search queries, so findTextInFiles can respect isWordMatch correctly * oss updates for endgame * Fix unit tests * fixes #55522 * Avoid missing manifest error from bubbling up #54757 * Settings format crawl * Search provider - Fix FileSearchProvider to return array, not progress * Fix #55598 * Settings editor - fix NPE rendering settings with no description * dont render inden guides in search box (#55600) * fixes #55454 * More settings crawl * Another change for #55598 - maxResults applies to FileSearch and TextSearch but not FileIndex * Fix FileSearchProvider unit tests for progress change * fixes #55561 * Settings description update for #54690 * Update setting descriptions for online services * Minor edits * fixes #55513 * fixes #55451 * Fix #55612 - fix findTextInFiles cancellation * fixes #55539 * More setting description tweaks * Setting to disable online experiments #54354 * fixes #55507 * fixes #55515 * Show online services action only in Insiders for now * Settings editor - change toc behavior default to 'filter' * Settings editor - nicer filter count style during search * Fix #55617 - search viewlet icons * Settings editor - better styling for element count indicator * SearchProvider - fix NPE when searching extraFileResources * Allow extends to work without json suffix Fixes #16905 * Remove accessability options logic entirely Follow up on #55451 * use latest version of DAP * fixes #55490 * fixes #55122 * fixes #52332 * Avoid assumptions about git: URIs (fixes #36236) * relative path for descriptions * resourece: get rid of isFile context key fixes #48275 * Register previous ids for compatibility (#53497) * more tuning for #48275 * no need to always re-read "files explorer" fixes #52003 * read out active composites properly fixes #51967 * Update link colors for hc theme to meet color contrast ratio, fixes #55651 Also updated link color for `textLinkActiveForeground` to be the same as `textLinkForeground` as it wasn't properly updated * detect 'winpty-agent.exe'; fixes #55672 * node-debug@1.26.7 * reset counter on new label * Settings editor - fix multiple setting links in one description * Settings editor - color code blocks in setting descriptions, fix #55532 * Settings editor - hover color in TOC * Settings editor - fix navigation NPE * Settings editor - fix text control width * Settings editor - maybe fix #55684 * Fix bug causing cursor to not move on paste * fixes #53582 * Use ctrlCmd instead of ctrl for go down from search box * fixes #55264 * fixes #55456 * filter for spcaes before triggering search (#55611) * Fix #55698 - don't lose filtered TOC counts when refreshing TOC * fixes #55421 * fixes #28979 * fixes #55576 * only add check for updates to windows/linux help * readonly files: append decoration to label fixes #53022 * debug: do not show toolbar while initialising fixes #55026 * Opening launch.json should not activate debug extensions fixes #55029 * fixes #55435 * fixes #55434 * fixes #55439 * trigger menu only on altkey up * Fix #50555 - fix settings editor memory leak * Fix #55712 - no need to focus 'a' anymore when restoring control focus after tree render * fixes #55335 * proper fix for readonly model fixes #53022 * improve FoldingRangeKind spec (for #55686) * Use class with static fields (fixes #55494) * Fixes #53671 * fixes #54630 * [html] should disable ionic suggestions by default. Currently forces deprecated Ionic v1 suggestions in .html files while typing. Fixes #53324 * cleanup deps * debug issues back to andre * update electron for smoketest * Fix #55757 - prevent settings tabs from overflowing * Fix #53897 - revert setting menu defaults to old editor * Add enum descriptions to `typescript.preferences.importModuleSpecifier` * Fix #55767 - leaking style elements from settings editor * Fix #55521 - prevent flashing when clicking in exclude control * Update Git modified color for contrast ratio, fixes #53140 * Revert "Merge branch 'master' of github.com:Microsoft/vscode" This reverts commit bf46b6bfbae0cab99c2863e1244a916181fa9fbc, reversing changes made to e275a424483dfb4ed33b428c97d5e2c441d6b917. * Revert "Revert "Merge branch 'master' of github.com:Microsoft/vscode"" This reverts commit 53949d963f39e40757557c6526332354a31d9154. * don't ask to install an incomplete menu * Fix NPE in terminal AccessibilityManager Fixes #55744 * don't display fallback menu unless we've closed the last window * fixes #55547 * Fix smoke tests for extension search box * Update OSSREADME.json for Electron 2.0.5 * Update distro Includes Chromium license changes * fix #55455 * fix #55865 * fixes #55893 * Fix bug causing workspace recommendations to go away upon ignoring a recommendation (#55805) * Fix bug causing workspace recommendations to go away upon ignoring a recommendation * ONly show on @recommended or @recommended:workspace * Make more consistant * Fix #55911 * Understand json activity (#55926) * Understand json file activity * Refactoring * adding composer.json * Distro update for experiments * use terminal.processId for auto-attach; fixes #55918 * Reject invalid URI with vscode.openFolder (for #55891) * improve win32 setup system vs user detection fixes #55840 fixes #55840 delay winreg import related to #55840 show notification earlier related to #55840 fix #55840 update inno setup message related to #55840 * Fix #55593 - this code only operates on local paths, so use fsPath and Uri.file instead * Bring back the old menu due to electron 2.0 issues (#55913) * add the old menu back for native menus * make menu labels match * `vscode.openFolder`: treat missing URI schema gracefully (for #55891) * delay EH reattach; fixes #55955 * Mark all json files under appSettingsHome as settings * Use localized strings for telemetry opt-out * Exception when saving file editor opened from remote file provider (fixes #55051) * Remove terminal menu from stable Fixes 56003 * VSCode Insiders crashes on open with TypeError: Cannot read property 'lastIndexOf' of undefined. Fixes #54933 * improve fix for #55891 * fix #55916 * Improve #55891 * increase EH debugging restart delay; fixes #55955 * Revert "Don't include non-resource entries in history quick pick" This reverts commit 37209a838e9f7e9abe6dc53ed73cdf1e03b72060. * Diff editor: horizontal scrollbar height is smaller (fixes #56062) * improve openFolder uri fix (correctly treat backslashes) * fixes #56116 repair ipc for native menubar keybindings * Fix #56240 - Open the JSON settings editor instead of the UI editor * Fix #55536 * uriDisplay: if no formatter is registered fall back to getPathlabel fixes #56104 * VSCode hangs when opening python file. Fixes #56377 * VS Code Hangs When Opening Specific PowerShell File. Fixes #56430 * Fix #56433 - search extraFileResources even when no folders open * Workaround #55649 * Fix in master #56371 * Fix tests #56371 * Fix in master #56317 * increase version to 1.26.1 * Fixes #56387: Handle SIGPIPE in extension host * fixes #56185 * Fix merge issues (part 1) * Fix build breaks (part 1) * Build breaks (part 2) * Build breaks (part 3) * More build breaks (part 4) * Fix build breaks (part 5) * WIP * Fix menus * Render query result and message panels (#2363) * Put back query editor hot exit changes * Fix grid changes that broke profiler (#2365) * Update APIs for saving query editor state * Fix restore view state for profiler and edit data * Updating custom default themes to support 4.5:1 contrast ratio * Test updates * Fix Extension Manager and Windows Setup * Update license headers * Add appveyor and travis files back * Fix hidden modal dropdown issue
This commit is contained in:
@@ -5,10 +5,11 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import { fuzzyScore, fuzzyScoreGracefulAggressive, skipScore } from 'vs/base/common/filters';
|
||||
import { ISuggestSupport, ISuggestResult } from 'vs/editor/common/modes';
|
||||
import { ISuggestionItem, SnippetConfig } from './suggest';
|
||||
import { fuzzyScore, fuzzyScoreGracefulAggressive, anyScore } from 'vs/base/common/filters';
|
||||
import { isDisposable } from 'vs/base/common/lifecycle';
|
||||
import { ISuggestResult, ISuggestSupport } from 'vs/editor/common/modes';
|
||||
import { ISuggestionItem } from './suggest';
|
||||
import { InternalSuggestOptions, EDITOR_DEFAULTS } from 'vs/editor/common/config/editorOptions';
|
||||
|
||||
export interface ICompletionItem extends ISuggestionItem {
|
||||
matches?: number[];
|
||||
@@ -46,25 +47,27 @@ const enum Refilter {
|
||||
|
||||
export class CompletionModel {
|
||||
|
||||
private readonly _column: number;
|
||||
private readonly _items: ICompletionItem[];
|
||||
private readonly _column: number;
|
||||
private readonly _options: InternalSuggestOptions;
|
||||
private readonly _snippetCompareFn = CompletionModel._compareCompletionItems;
|
||||
|
||||
private _lineContext: LineContext;
|
||||
private _refilterKind: Refilter;
|
||||
private _filteredItems: ICompletionItem[];
|
||||
private _isIncomplete: boolean;
|
||||
private _isIncomplete: Set<ISuggestSupport>;
|
||||
private _stats: ICompletionStats;
|
||||
|
||||
constructor(items: ISuggestionItem[], column: number, lineContext: LineContext, snippetConfig?: SnippetConfig) {
|
||||
constructor(items: ISuggestionItem[], column: number, lineContext: LineContext, options: InternalSuggestOptions = EDITOR_DEFAULTS.contribInfo.suggest) {
|
||||
this._items = items;
|
||||
this._column = column;
|
||||
this._options = options;
|
||||
this._refilterKind = Refilter.All;
|
||||
this._lineContext = lineContext;
|
||||
|
||||
if (snippetConfig === 'top') {
|
||||
if (options.snippets === 'top') {
|
||||
this._snippetCompareFn = CompletionModel._compareCompletionItemsSnippetsUp;
|
||||
} else if (snippetConfig === 'bottom') {
|
||||
} else if (options.snippets === 'bottom') {
|
||||
this._snippetCompareFn = CompletionModel._compareCompletionItemsSnippetsDown;
|
||||
}
|
||||
}
|
||||
@@ -99,24 +102,27 @@ export class CompletionModel {
|
||||
return this._filteredItems;
|
||||
}
|
||||
|
||||
get incomplete(): boolean {
|
||||
get incomplete(): Set<ISuggestSupport> {
|
||||
this._ensureCachedState();
|
||||
return this._isIncomplete;
|
||||
}
|
||||
|
||||
resolveIncompleteInfo(): { incomplete: ISuggestSupport[], complete: ISuggestionItem[] } {
|
||||
const incomplete: ISuggestSupport[] = [];
|
||||
const complete: ISuggestionItem[] = [];
|
||||
adopt(except: Set<ISuggestSupport>): ISuggestionItem[] {
|
||||
let res = new Array<ISuggestionItem>();
|
||||
for (let i = 0; i < this._items.length;) {
|
||||
if (!except.has(this._items[i].support)) {
|
||||
res.push(this._items[i]);
|
||||
|
||||
for (const item of this._items) {
|
||||
if (!item.container.incomplete) {
|
||||
complete.push(item);
|
||||
} else if (incomplete.indexOf(item.support) < 0) {
|
||||
incomplete.push(item.support);
|
||||
// unordered removed
|
||||
this._items[i] = this._items[this._items.length - 1];
|
||||
this._items.pop();
|
||||
} else {
|
||||
// continue with next item
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return { incomplete, complete };
|
||||
this._refilterKind = Refilter.All;
|
||||
return res;
|
||||
}
|
||||
|
||||
get stats(): ICompletionStats {
|
||||
@@ -132,7 +138,7 @@ export class CompletionModel {
|
||||
|
||||
private _createCachedState(): void {
|
||||
|
||||
this._isIncomplete = false;
|
||||
this._isIncomplete = new Set();
|
||||
this._stats = { suggestionCount: 0, snippetCount: 0, textCount: 0 };
|
||||
|
||||
const { leadingLineContent, characterCountDelta } = this._lineContext;
|
||||
@@ -143,8 +149,9 @@ export class CompletionModel {
|
||||
const target: typeof source = [];
|
||||
|
||||
// picks a score function based on the number of
|
||||
// items that we have to score/filter
|
||||
const scoreFn = source.length > 2000 ? fuzzyScore : fuzzyScoreGracefulAggressive;
|
||||
// items that we have to score/filter and based on the
|
||||
// user-configuration
|
||||
const scoreFn = (!this._options.filterGraceful || source.length > 2000) ? fuzzyScore : fuzzyScoreGracefulAggressive;
|
||||
|
||||
for (let i = 0; i < source.length; i++) {
|
||||
|
||||
@@ -153,7 +160,9 @@ export class CompletionModel {
|
||||
|
||||
// collect those supports that signaled having
|
||||
// an incomplete result
|
||||
this._isIncomplete = this._isIncomplete || container.incomplete;
|
||||
if (container.incomplete) {
|
||||
this._isIncomplete.add(item.support);
|
||||
}
|
||||
|
||||
// 'word' is that remainder of the current line that we
|
||||
// filter and score against. In theory each suggestion uses a
|
||||
@@ -186,7 +195,7 @@ export class CompletionModel {
|
||||
continue;
|
||||
}
|
||||
item.score = match[0];
|
||||
item.matches = skipScore(word, suggestion.label)[1];
|
||||
item.matches = (fuzzyScore(word, suggestion.label) || anyScore(word, suggestion.label))[1];
|
||||
|
||||
} else {
|
||||
// by default match `word` against the `label`
|
||||
|
||||
@@ -2,14 +2,12 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { sequence, asWinJsPromise } from 'vs/base/common/async';
|
||||
import { first2 } from 'vs/base/common/async';
|
||||
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
|
||||
import { compareIgnoreCase } from 'vs/base/common/strings';
|
||||
import { assign } from 'vs/base/common/objects';
|
||||
import { onUnexpectedExternalError } from 'vs/base/common/errors';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IEditorContribution } from 'vs/editor/common/editorCommon';
|
||||
import { ITextModel } from 'vs/editor/common/model';
|
||||
import { registerDefaultLanguageCommand } from 'vs/editor/browser/editorExtensions';
|
||||
@@ -17,6 +15,7 @@ import { ISuggestResult, ISuggestSupport, ISuggestion, SuggestRegistry, SuggestC
|
||||
import { Position, IPosition } from 'vs/editor/common/core/position';
|
||||
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
|
||||
export const Context = {
|
||||
Visible: new RawContextKey<boolean>('suggestWidgetVisible', false),
|
||||
@@ -31,20 +30,31 @@ export interface ISuggestionItem {
|
||||
suggestion: ISuggestion;
|
||||
container: ISuggestResult;
|
||||
support: ISuggestSupport;
|
||||
resolve(): TPromise<void>;
|
||||
resolve(token: CancellationToken): Thenable<void>;
|
||||
}
|
||||
|
||||
export type SnippetConfig = 'top' | 'bottom' | 'inline' | 'none';
|
||||
|
||||
let _snippetSuggestSupport: ISuggestSupport;
|
||||
|
||||
export function getSnippetSuggestSupport(): ISuggestSupport {
|
||||
return _snippetSuggestSupport;
|
||||
}
|
||||
|
||||
export function setSnippetSuggestSupport(support: ISuggestSupport): ISuggestSupport {
|
||||
const old = _snippetSuggestSupport;
|
||||
_snippetSuggestSupport = support;
|
||||
return old;
|
||||
}
|
||||
|
||||
export function provideSuggestionItems(model: ITextModel, position: Position, snippetConfig: SnippetConfig = 'bottom', onlyFrom?: ISuggestSupport[], context?: SuggestContext): TPromise<ISuggestionItem[]> {
|
||||
export function provideSuggestionItems(
|
||||
model: ITextModel,
|
||||
position: Position,
|
||||
snippetConfig: SnippetConfig = 'bottom',
|
||||
onlyFrom?: ISuggestSupport[],
|
||||
context?: SuggestContext,
|
||||
token: CancellationToken = CancellationToken.None
|
||||
): Promise<ISuggestionItem[]> {
|
||||
|
||||
const allSuggestions: ISuggestionItem[] = [];
|
||||
const acceptSuggestion = createSuggesionFilter(snippetConfig);
|
||||
@@ -64,50 +74,44 @@ export function provideSuggestionItems(model: ITextModel, position: Position, sn
|
||||
// add suggestions from contributed providers - providers are ordered in groups of
|
||||
// equal score and once a group produces a result the process stops
|
||||
let hasResult = false;
|
||||
const factory = supports.map(supports => {
|
||||
return () => {
|
||||
// stop when we have a result
|
||||
if (hasResult) {
|
||||
const factory = supports.map(supports => () => {
|
||||
// for each support in the group ask for suggestions
|
||||
return Promise.all(supports.map(support => {
|
||||
|
||||
if (!isFalsyOrEmpty(onlyFrom) && onlyFrom.indexOf(support) < 0) {
|
||||
return undefined;
|
||||
}
|
||||
// for each support in the group ask for suggestions
|
||||
return TPromise.join(supports.map(support => {
|
||||
|
||||
if (!isFalsyOrEmpty(onlyFrom) && onlyFrom.indexOf(support) < 0) {
|
||||
return undefined;
|
||||
}
|
||||
return Promise.resolve(support.provideCompletionItems(model, position, suggestConext, token)).then(container => {
|
||||
|
||||
return asWinJsPromise(token => support.provideCompletionItems(model, position, suggestConext, token)).then(container => {
|
||||
const len = allSuggestions.length;
|
||||
|
||||
const len = allSuggestions.length;
|
||||
if (container && !isFalsyOrEmpty(container.suggestions)) {
|
||||
for (let suggestion of container.suggestions) {
|
||||
if (acceptSuggestion(suggestion)) {
|
||||
|
||||
if (container && !isFalsyOrEmpty(container.suggestions)) {
|
||||
for (let suggestion of container.suggestions) {
|
||||
if (acceptSuggestion(suggestion)) {
|
||||
fixOverwriteBeforeAfter(suggestion, container);
|
||||
|
||||
fixOverwriteBeforeAfter(suggestion, container);
|
||||
|
||||
allSuggestions.push({
|
||||
position,
|
||||
container,
|
||||
suggestion,
|
||||
support,
|
||||
resolve: createSuggestionResolver(support, suggestion, model, position)
|
||||
});
|
||||
}
|
||||
allSuggestions.push({
|
||||
position,
|
||||
container,
|
||||
suggestion,
|
||||
support,
|
||||
resolve: createSuggestionResolver(support, suggestion, model, position)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (len !== allSuggestions.length && support !== _snippetSuggestSupport) {
|
||||
hasResult = true;
|
||||
}
|
||||
if (len !== allSuggestions.length && support !== _snippetSuggestSupport) {
|
||||
hasResult = true;
|
||||
}
|
||||
|
||||
}, onUnexpectedExternalError);
|
||||
}));
|
||||
};
|
||||
}, onUnexpectedExternalError);
|
||||
}));
|
||||
});
|
||||
|
||||
const result = sequence(factory).then(() => allSuggestions.sort(getSuggestionComparator(snippetConfig)));
|
||||
const result = first2(factory, () => hasResult).then(() => allSuggestions.sort(getSuggestionComparator(snippetConfig)));
|
||||
|
||||
// result.then(items => {
|
||||
// console.log(model.getWordUntilPosition(position), items.map(item => `${item.suggestion.label}, type=${item.suggestion.type}, incomplete?${item.container.incomplete}, overwriteBefore=${item.suggestion.overwriteBefore}`));
|
||||
@@ -128,13 +132,13 @@ function fixOverwriteBeforeAfter(suggestion: ISuggestion, container: ISuggestRes
|
||||
}
|
||||
}
|
||||
|
||||
function createSuggestionResolver(provider: ISuggestSupport, suggestion: ISuggestion, model: ITextModel, position: Position): () => TPromise<void> {
|
||||
return () => {
|
||||
function createSuggestionResolver(provider: ISuggestSupport, suggestion: ISuggestion, model: ITextModel, position: Position): (token: CancellationToken) => Promise<void> {
|
||||
return (token) => {
|
||||
if (typeof provider.resolveCompletionItem === 'function') {
|
||||
return asWinJsPromise(token => provider.resolveCompletionItem(model, position, suggestion, token))
|
||||
.then(value => { assign(suggestion, value); });
|
||||
return Promise.resolve(provider.resolveCompletionItem(model, position, suggestion, token)).then(value => { assign(suggestion, value); });
|
||||
} else {
|
||||
return Promise.resolve(void 0);
|
||||
}
|
||||
return TPromise.as(void 0);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -216,13 +220,13 @@ registerDefaultLanguageCommand('_executeCompletionItemProvider', (model, positio
|
||||
return provideSuggestionItems(model, position).then(items => {
|
||||
for (const item of items) {
|
||||
if (resolving.length < maxItemsToResolve) {
|
||||
resolving.push(item.resolve());
|
||||
resolving.push(item.resolve(CancellationToken.None));
|
||||
}
|
||||
result.incomplete = result.incomplete || item.container.incomplete;
|
||||
result.suggestions.push(item.suggestion);
|
||||
}
|
||||
}).then(() => {
|
||||
return TPromise.join(resolving);
|
||||
return Promise.all(resolving);
|
||||
}).then(() => {
|
||||
return result;
|
||||
});
|
||||
@@ -232,10 +236,16 @@ interface SuggestController extends IEditorContribution {
|
||||
triggerSuggest(onlyFrom?: ISuggestSupport[]): void;
|
||||
}
|
||||
|
||||
let _suggestions: ISuggestion[];
|
||||
|
||||
let _provider = new class implements ISuggestSupport {
|
||||
|
||||
onlyOnceSuggestions: ISuggestion[] = [];
|
||||
|
||||
provideCompletionItems(): ISuggestResult {
|
||||
return _suggestions && { suggestions: _suggestions };
|
||||
let suggestions = this.onlyOnceSuggestions.slice(0);
|
||||
let result = { suggestions };
|
||||
this.onlyOnceSuggestions.length = 0;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -243,8 +253,7 @@ SuggestRegistry.register('*', _provider);
|
||||
|
||||
export function showSimpleSuggestions(editor: ICodeEditor, suggestions: ISuggestion[]) {
|
||||
setTimeout(() => {
|
||||
_suggestions = suggestions;
|
||||
_provider.onlyOnceSuggestions.push(...suggestions);
|
||||
editor.getContribution<SuggestController>('editor.contrib.suggestController').triggerSuggest([_provider]);
|
||||
_suggestions = undefined;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import { Context as SuggestContext } from './suggest';
|
||||
import { SuggestModel, State } from './suggestModel';
|
||||
import { ICompletionItem } from './completionModel';
|
||||
import { SuggestWidget, ISelectedSuggestion } from './suggestWidget';
|
||||
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { SuggestMemories } from 'vs/editor/contrib/suggest/suggestMemory';
|
||||
|
||||
class AcceptOnCharacterOracle {
|
||||
@@ -196,10 +196,12 @@ export class SuggestController implements IEditorContribution {
|
||||
const editorColumn = this._editor.getPosition().column;
|
||||
const columnDelta = editorColumn - position.column;
|
||||
|
||||
// pushing undo stops *before* additional text edits and
|
||||
// *after* the main edit
|
||||
this._editor.pushUndoStop();
|
||||
|
||||
if (Array.isArray(suggestion.additionalTextEdits)) {
|
||||
this._editor.pushUndoStop();
|
||||
this._editor.executeEdits('suggestController.additionalTextEdits', suggestion.additionalTextEdits.map(edit => EditOperation.replace(Range.lift(edit.range), edit.text)));
|
||||
this._editor.pushUndoStop();
|
||||
}
|
||||
|
||||
// keep item in memory
|
||||
@@ -213,9 +215,12 @@ export class SuggestController implements IEditorContribution {
|
||||
SnippetController2.get(this._editor).insert(
|
||||
insertText,
|
||||
suggestion.overwriteBefore + columnDelta,
|
||||
suggestion.overwriteAfter
|
||||
suggestion.overwriteAfter,
|
||||
false, false
|
||||
);
|
||||
|
||||
this._editor.pushUndoStop();
|
||||
|
||||
if (!suggestion.command) {
|
||||
// done
|
||||
this._model.cancel();
|
||||
@@ -320,7 +325,8 @@ export class TriggerSuggestAction extends EditorAction {
|
||||
kbOpts: {
|
||||
kbExpr: EditorContextKeys.textInputFocus,
|
||||
primary: KeyMod.CtrlCmd | KeyCode.Space,
|
||||
mac: { primary: KeyMod.WinCtrl | KeyCode.Space }
|
||||
mac: { primary: KeyMod.WinCtrl | KeyCode.Space },
|
||||
weight: KeybindingWeight.EditorContrib
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -339,7 +345,7 @@ export class TriggerSuggestAction extends EditorAction {
|
||||
registerEditorContribution(SuggestController);
|
||||
registerEditorAction(TriggerSuggestAction);
|
||||
|
||||
const weight = KeybindingsRegistry.WEIGHT.editorContrib(90);
|
||||
const weight = KeybindingWeight.EditorContrib + 90;
|
||||
|
||||
const SuggestCommand = EditorCommand.bindToContribution<SuggestController>(SuggestController.get);
|
||||
|
||||
|
||||
@@ -13,9 +13,26 @@ import { RunOnceScheduler } from 'vs/base/common/async';
|
||||
|
||||
export abstract class Memory {
|
||||
|
||||
abstract memorize(model: ITextModel, pos: IPosition, item: ICompletionItem): void;
|
||||
select(model: ITextModel, pos: IPosition, items: ICompletionItem[]): number {
|
||||
if (items.length === 0) {
|
||||
return 0;
|
||||
}
|
||||
let topScore = items[0].score;
|
||||
for (let i = 1; i < items.length; i++) {
|
||||
const { score, suggestion } = items[i];
|
||||
if (score !== topScore) {
|
||||
// stop when leaving the group of top matches
|
||||
break;
|
||||
}
|
||||
if (suggestion.preselect) {
|
||||
// stop when seeing an auto-select-item
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
abstract select(model: ITextModel, pos: IPosition, items: ICompletionItem[]): number;
|
||||
abstract memorize(model: ITextModel, pos: IPosition, item: ICompletionItem): void;
|
||||
|
||||
abstract toJSON(): object;
|
||||
|
||||
@@ -28,10 +45,6 @@ export class NoMemory extends Memory {
|
||||
// no-op
|
||||
}
|
||||
|
||||
select(model: ITextModel, pos: IPosition, items: ICompletionItem[]): number {
|
||||
return 0;
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return undefined;
|
||||
}
|
||||
@@ -67,15 +80,15 @@ export class LRUMemory extends Memory {
|
||||
// that has been used in the past
|
||||
let { word } = model.getWordUntilPosition(pos);
|
||||
if (word.length !== 0) {
|
||||
return 0;
|
||||
return super.select(model, pos, items);
|
||||
}
|
||||
|
||||
let lineSuffix = model.getLineContent(pos.lineNumber).substr(pos.column - 10, pos.column - 1);
|
||||
if (/\s$/.test(lineSuffix)) {
|
||||
return 0;
|
||||
return super.select(model, pos, items);
|
||||
}
|
||||
|
||||
let res = 0;
|
||||
let res = -1;
|
||||
let seq = -1;
|
||||
for (let i = 0; i < items.length; i++) {
|
||||
const { suggestion } = items[i];
|
||||
@@ -86,7 +99,11 @@ export class LRUMemory extends Memory {
|
||||
res = i;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
if (res === -1) {
|
||||
return super.select(model, pos, items);
|
||||
} else {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
toJSON(): object {
|
||||
@@ -127,7 +144,7 @@ export class PrefixMemory extends Memory {
|
||||
select(model: ITextModel, pos: IPosition, items: ICompletionItem[]): number {
|
||||
let { word } = model.getWordUntilPosition(pos);
|
||||
if (!word) {
|
||||
return 0;
|
||||
return super.select(model, pos, items);
|
||||
}
|
||||
let key = `${model.getLanguageIdentifier().language}/${word}`;
|
||||
let item = this._trie.get(key);
|
||||
@@ -142,7 +159,7 @@ export class PrefixMemory extends Memory {
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return super.select(model, pos, items);
|
||||
}
|
||||
|
||||
toJSON(): object {
|
||||
|
||||
@@ -4,20 +4,21 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { isFalsyOrEmpty } from 'vs/base/common/arrays';
|
||||
import { TimeoutTimer } from 'vs/base/common/async';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { TimeoutTimer, CancelablePromise, createCancelablePromise } from 'vs/base/common/async';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { ITextModel, IWordAtPosition } from 'vs/editor/common/model';
|
||||
import { ISuggestSupport, SuggestRegistry, StandardTokenType, SuggestTriggerKind, SuggestContext } from 'vs/editor/common/modes';
|
||||
import { values } from 'vs/base/common/map';
|
||||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { CursorChangeReason, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
|
||||
import { Position } from 'vs/editor/common/core/position';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { provideSuggestionItems, getSuggestionComparator, ISuggestionItem } from './suggest';
|
||||
import { ITextModel, IWordAtPosition } from 'vs/editor/common/model';
|
||||
import { ISuggestSupport, StandardTokenType, SuggestContext, SuggestRegistry, SuggestTriggerKind } from 'vs/editor/common/modes';
|
||||
import { CompletionModel } from './completionModel';
|
||||
import { CursorChangeReason, ICursorSelectionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
|
||||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { ISuggestionItem, getSuggestionComparator, provideSuggestionItems, getSnippetSuggestSupport } from './suggest';
|
||||
import { SnippetController2 } from 'vs/editor/contrib/snippet/snippetController2';
|
||||
|
||||
export interface ICancelEvent {
|
||||
readonly retrigger: boolean;
|
||||
@@ -88,11 +89,11 @@ export class SuggestModel implements IDisposable {
|
||||
private _toDispose: IDisposable[] = [];
|
||||
private _quickSuggestDelay: number;
|
||||
private _triggerCharacterListener: IDisposable;
|
||||
private _triggerAutoSuggestPromise: TPromise<void>;
|
||||
private _triggerRefilter = new TimeoutTimer();
|
||||
private readonly _triggerQuickSuggest = new TimeoutTimer();
|
||||
private readonly _triggerRefilter = new TimeoutTimer();
|
||||
private _state: State;
|
||||
|
||||
private _requestPromise: TPromise<void>;
|
||||
private _requestPromise: CancelablePromise<ISuggestionItem[]>;
|
||||
private _context: LineContext;
|
||||
private _currentSelection: Selection;
|
||||
|
||||
@@ -108,7 +109,6 @@ export class SuggestModel implements IDisposable {
|
||||
constructor(editor: ICodeEditor) {
|
||||
this._editor = editor;
|
||||
this._state = State.Idle;
|
||||
this._triggerAutoSuggestPromise = null;
|
||||
this._requestPromise = null;
|
||||
this._completionModel = null;
|
||||
this._context = null;
|
||||
@@ -143,7 +143,7 @@ export class SuggestModel implements IDisposable {
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
dispose([this._onDidCancel, this._onDidSuggest, this._onDidTrigger, this._triggerCharacterListener, this._triggerRefilter]);
|
||||
dispose([this._onDidCancel, this._onDidSuggest, this._onDidTrigger, this._triggerCharacterListener, this._triggerQuickSuggest, this._triggerRefilter]);
|
||||
this._toDispose = dispose(this._toDispose);
|
||||
dispose(this._completionModel);
|
||||
this.cancel();
|
||||
@@ -170,18 +170,18 @@ export class SuggestModel implements IDisposable {
|
||||
return;
|
||||
}
|
||||
|
||||
const supportsByTriggerCharacter: { [ch: string]: ISuggestSupport[] } = Object.create(null);
|
||||
const supportsByTriggerCharacter: { [ch: string]: Set<ISuggestSupport> } = Object.create(null);
|
||||
for (const support of SuggestRegistry.all(this._editor.getModel())) {
|
||||
if (isFalsyOrEmpty(support.triggerCharacters)) {
|
||||
continue;
|
||||
}
|
||||
for (const ch of support.triggerCharacters) {
|
||||
const array = supportsByTriggerCharacter[ch];
|
||||
if (!array) {
|
||||
supportsByTriggerCharacter[ch] = [support];
|
||||
} else {
|
||||
array.push(support);
|
||||
let set = supportsByTriggerCharacter[ch];
|
||||
if (!set) {
|
||||
set = supportsByTriggerCharacter[ch] = new Set();
|
||||
set.add(getSnippetSuggestSupport());
|
||||
}
|
||||
set.add(support);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,15 +192,8 @@ export class SuggestModel implements IDisposable {
|
||||
if (supports) {
|
||||
// keep existing items that where not computed by the
|
||||
// supports/providers that want to trigger now
|
||||
const items: ISuggestionItem[] = [];
|
||||
if (this._completionModel) {
|
||||
for (const item of this._completionModel.items) {
|
||||
if (supports.indexOf(item.support) < 0) {
|
||||
items.push(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.trigger({ auto: true, triggerCharacter: lastChar }, Boolean(this._completionModel), supports, items);
|
||||
const items: ISuggestionItem[] = this._completionModel ? this._completionModel.adopt(supports) : undefined;
|
||||
this.trigger({ auto: true, triggerCharacter: lastChar }, Boolean(this._completionModel), values(supports), items);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -215,9 +208,9 @@ export class SuggestModel implements IDisposable {
|
||||
|
||||
this._triggerRefilter.cancel();
|
||||
|
||||
if (this._triggerAutoSuggestPromise) {
|
||||
this._triggerAutoSuggestPromise.cancel();
|
||||
this._triggerAutoSuggestPromise = null;
|
||||
if (this._triggerQuickSuggest) {
|
||||
this._triggerQuickSuggest.cancel();
|
||||
|
||||
}
|
||||
|
||||
if (this._requestPromise) {
|
||||
@@ -271,48 +264,58 @@ export class SuggestModel implements IDisposable {
|
||||
|
||||
if (this._state === State.Idle) {
|
||||
|
||||
// trigger 24x7 IntelliSense when idle, enabled, when cursor
|
||||
// moved RIGHT, and when at a good position
|
||||
if (this._editor.getConfiguration().contribInfo.quickSuggestions !== false
|
||||
&& (prevSelection.containsRange(this._currentSelection)
|
||||
|| prevSelection.getEndPosition().isBeforeOrEqual(this._currentSelection.getPosition()))
|
||||
) {
|
||||
this.cancel();
|
||||
|
||||
this._triggerAutoSuggestPromise = TPromise.timeout(this._quickSuggestDelay);
|
||||
this._triggerAutoSuggestPromise.then(() => {
|
||||
if (LineContext.shouldAutoTrigger(this._editor)) {
|
||||
const model = this._editor.getModel();
|
||||
const pos = this._editor.getPosition();
|
||||
|
||||
if (!model) {
|
||||
return;
|
||||
}
|
||||
// validate enabled now
|
||||
const { quickSuggestions } = this._editor.getConfiguration().contribInfo;
|
||||
if (quickSuggestions === false) {
|
||||
return;
|
||||
} else if (quickSuggestions === true) {
|
||||
// all good
|
||||
} else {
|
||||
// Check the type of the token that triggered this
|
||||
model.tokenizeIfCheap(pos.lineNumber);
|
||||
const lineTokens = model.getLineTokens(pos.lineNumber);
|
||||
const tokenType = lineTokens.getStandardTokenType(lineTokens.findTokenIndexAtOffset(Math.max(pos.column - 1 - 1, 0)));
|
||||
const inValidScope = quickSuggestions.other && tokenType === StandardTokenType.Other
|
||||
|| quickSuggestions.comments && tokenType === StandardTokenType.Comment
|
||||
|| quickSuggestions.strings && tokenType === StandardTokenType.String;
|
||||
|
||||
if (!inValidScope) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.trigger({ auto: true });
|
||||
}
|
||||
this._triggerAutoSuggestPromise = null;
|
||||
});
|
||||
if (this._editor.getConfiguration().contribInfo.quickSuggestions === false) {
|
||||
// not enabled
|
||||
return;
|
||||
}
|
||||
|
||||
if (!prevSelection.containsRange(this._currentSelection) && !prevSelection.getEndPosition().isBeforeOrEqual(this._currentSelection.getPosition())) {
|
||||
// cursor didn't move RIGHT
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._editor.getConfiguration().contribInfo.suggest.snippetsPreventQuickSuggestions && SnippetController2.get(this._editor).isInSnippet()) {
|
||||
// no quick suggestion when in snippet mode
|
||||
return;
|
||||
}
|
||||
|
||||
this.cancel();
|
||||
|
||||
this._triggerQuickSuggest.cancelAndSet(() => {
|
||||
if (!LineContext.shouldAutoTrigger(this._editor)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const model = this._editor.getModel();
|
||||
const pos = this._editor.getPosition();
|
||||
if (!model) {
|
||||
return;
|
||||
}
|
||||
// validate enabled now
|
||||
const { quickSuggestions } = this._editor.getConfiguration().contribInfo;
|
||||
if (quickSuggestions === false) {
|
||||
return;
|
||||
} else if (quickSuggestions === true) {
|
||||
// all good
|
||||
} else {
|
||||
// Check the type of the token that triggered this
|
||||
model.tokenizeIfCheap(pos.lineNumber);
|
||||
const lineTokens = model.getLineTokens(pos.lineNumber);
|
||||
const tokenType = lineTokens.getStandardTokenType(lineTokens.findTokenIndexAtOffset(Math.max(pos.column - 1 - 1, 0)));
|
||||
const inValidScope = quickSuggestions.other && tokenType === StandardTokenType.Other
|
||||
|| quickSuggestions.comments && tokenType === StandardTokenType.Comment
|
||||
|| quickSuggestions.strings && tokenType === StandardTokenType.String;
|
||||
|
||||
if (!inValidScope) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// we made it till here -> trigger now
|
||||
this.trigger({ auto: true });
|
||||
|
||||
}, this._quickSuggestDelay);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,11 +365,16 @@ export class SuggestModel implements IDisposable {
|
||||
suggestCtx = { triggerKind: SuggestTriggerKind.Invoke };
|
||||
}
|
||||
|
||||
this._requestPromise = provideSuggestionItems(model, this._editor.getPosition(),
|
||||
this._editor.getConfiguration().contribInfo.snippetSuggestions,
|
||||
this._requestPromise = createCancelablePromise(token => provideSuggestionItems(
|
||||
model,
|
||||
this._editor.getPosition(),
|
||||
this._editor.getConfiguration().contribInfo.suggest.snippets,
|
||||
onlyFrom,
|
||||
suggestCtx
|
||||
).then(items => {
|
||||
suggestCtx,
|
||||
token
|
||||
));
|
||||
|
||||
this._requestPromise.then(items => {
|
||||
|
||||
this._requestPromise = null;
|
||||
if (this._state === State.Idle) {
|
||||
@@ -378,7 +386,7 @@ export class SuggestModel implements IDisposable {
|
||||
}
|
||||
|
||||
if (!isFalsyOrEmpty(existingItems)) {
|
||||
const cmpFn = getSuggestionComparator(this._editor.getConfiguration().contribInfo.snippetSuggestions);
|
||||
const cmpFn = getSuggestionComparator(this._editor.getConfiguration().contribInfo.suggest.snippets);
|
||||
items = items.concat(existingItems).sort(cmpFn);
|
||||
}
|
||||
|
||||
@@ -387,10 +395,12 @@ export class SuggestModel implements IDisposable {
|
||||
this._completionModel = new CompletionModel(items, this._context.column, {
|
||||
leadingLineContent: ctx.leadingLineContent,
|
||||
characterCountDelta: this._context ? ctx.column - this._context.column : 0
|
||||
}, this._editor.getConfiguration().contribInfo.snippetSuggestions);
|
||||
},
|
||||
this._editor.getConfiguration().contribInfo.suggest
|
||||
);
|
||||
this._onNewContext(ctx);
|
||||
|
||||
}).then(null, onUnexpectedError);
|
||||
}).catch(onUnexpectedError);
|
||||
}
|
||||
|
||||
private _onNewContext(ctx: LineContext): void {
|
||||
@@ -427,10 +437,11 @@ export class SuggestModel implements IDisposable {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx.column > this._context.column && this._completionModel.incomplete && ctx.leadingWord.word.length !== 0) {
|
||||
if (ctx.column > this._context.column && this._completionModel.incomplete.size > 0 && ctx.leadingWord.word.length !== 0) {
|
||||
// typed -> moved cursor RIGHT & incomple model & still on a word -> retrigger
|
||||
const { complete, incomplete } = this._completionModel.resolveIncompleteInfo();
|
||||
this.trigger({ auto: this._state === State.Auto }, true, incomplete, complete);
|
||||
const { incomplete } = this._completionModel;
|
||||
const adopted = this._completionModel.adopt(incomplete);
|
||||
this.trigger({ auto: this._state === State.Auto }, true, values(incomplete), adopted);
|
||||
|
||||
} else {
|
||||
// typed -> moved cursor RIGHT -> update UI
|
||||
|
||||
@@ -10,12 +10,11 @@ import * as nls from 'vs/nls';
|
||||
import { createMatches } from 'vs/base/common/filters';
|
||||
import * as strings from 'vs/base/common/strings';
|
||||
import { Event, Emitter, chain } from 'vs/base/common/event';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { isPromiseCanceledError, onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { IDisposable, dispose, toDisposable } from 'vs/base/common/lifecycle';
|
||||
import { addClass, append, $, hide, removeClass, show, toggleClass, getDomNodePagePosition, hasClass } from 'vs/base/browser/dom';
|
||||
import { HighlightedLabel } from 'vs/base/browser/ui/highlightedlabel/highlightedLabel';
|
||||
import { IDelegate, IListEvent, IRenderer } from 'vs/base/browser/ui/list/list';
|
||||
import { IVirtualDelegate, IListEvent, IRenderer } from 'vs/base/browser/ui/list/list';
|
||||
import { List } from 'vs/base/browser/ui/list/listWidget';
|
||||
import { DomScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement';
|
||||
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
|
||||
@@ -33,6 +32,8 @@ import { IStorageService, StorageScope } from 'vs/platform/storage/common/storag
|
||||
import { MarkdownRenderer } from 'vs/editor/contrib/markdown/markdownRenderer';
|
||||
import { IModeService } from 'vs/editor/common/services/modeService';
|
||||
import { IOpenerService } from 'vs/platform/opener/common/opener';
|
||||
import { TimeoutTimer, CancelablePromise, createCancelablePromise } from 'vs/base/common/async';
|
||||
import { CancellationToken } from 'vs/base/common/cancellation';
|
||||
|
||||
const sticky = false; // for development purposes
|
||||
const expandSuggestionDocsByDefault = false;
|
||||
@@ -152,7 +153,7 @@ class Renderer implements IRenderer<ICompletionItem, ISuggestionTemplateData> {
|
||||
}
|
||||
}
|
||||
|
||||
data.highlightedLabel.set(suggestion.label, createMatches(element.matches));
|
||||
data.highlightedLabel.set(suggestion.label, createMatches(element.matches), '', true);
|
||||
// data.highlightedLabel.set(`${suggestion.label} <${element.score}=score(${element.word}, ${suggestion.filterText || suggestion.label})>`, createMatches(element.matches));
|
||||
data.typeLabel.textContent = (suggestion.detail || '').replace(/\n.*$/m, '');
|
||||
|
||||
@@ -172,7 +173,10 @@ class Renderer implements IRenderer<ICompletionItem, ISuggestionTemplateData> {
|
||||
data.readMore.onmousedown = null;
|
||||
data.readMore.onclick = null;
|
||||
}
|
||||
}
|
||||
|
||||
disposeElement(): void {
|
||||
// noop
|
||||
}
|
||||
|
||||
disposeTemplate(templateData: ISuggestionTemplateData): void {
|
||||
@@ -241,6 +245,8 @@ class SuggestionDetails {
|
||||
chain<IConfigurationChangedEvent>(this.editor.onDidChangeConfiguration.bind(this.editor))
|
||||
.filter(e => e.fontInfo)
|
||||
.on(this.configureFont, this, this.disposables);
|
||||
|
||||
markdownRenderer.onDidRenderCodeBlock(() => this.scrollbar.scanDomNode(), this, this.disposables);
|
||||
}
|
||||
|
||||
get element() {
|
||||
@@ -353,7 +359,7 @@ export interface ISelectedSuggestion {
|
||||
model: CompletionModel;
|
||||
}
|
||||
|
||||
export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>, IDisposable {
|
||||
export class SuggestWidget implements IContentWidget, IVirtualDelegate<ICompletionItem>, IDisposable {
|
||||
|
||||
private static readonly ID: string = 'editor.widget.suggestWidget';
|
||||
|
||||
@@ -366,7 +372,7 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
|
||||
private state: State;
|
||||
private isAuto: boolean;
|
||||
private loadingTimeout: number;
|
||||
private currentSuggestionDetails: TPromise<void>;
|
||||
private currentSuggestionDetails: CancelablePromise<void>;
|
||||
private focusedItem: ICompletionItem;
|
||||
private ignoreFocusEvents = false;
|
||||
private completionModel: CompletionModel;
|
||||
@@ -382,8 +388,8 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
|
||||
private suggestWidgetMultipleSuggestions: IContextKey<boolean>;
|
||||
private suggestionSupportsAutoAccept: IContextKey<boolean>;
|
||||
|
||||
private editorBlurTimeout: TPromise<void>;
|
||||
private showTimeout: TPromise<void>;
|
||||
private readonly editorBlurTimeout = new TimeoutTimer();
|
||||
private readonly showTimeout = new TimeoutTimer();
|
||||
private toDispose: IDisposable[];
|
||||
|
||||
private onDidSelectEmitter = new Emitter<ISelectedSuggestion>();
|
||||
@@ -406,6 +412,8 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
|
||||
private storageServiceAvailable: boolean = true;
|
||||
private expandSuggestionDocs: boolean = false;
|
||||
|
||||
private firstFocusInCurrentList: boolean = false;
|
||||
|
||||
constructor(
|
||||
private editor: ICodeEditor,
|
||||
@ITelemetryService private telemetryService: ITelemetryService,
|
||||
@@ -470,20 +478,6 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
|
||||
this.setState(State.Hidden);
|
||||
|
||||
this.onThemeChange(themeService.getTheme());
|
||||
|
||||
// TODO@Alex: this is useful, but spammy
|
||||
// var isVisible = false;
|
||||
// this.onDidVisibilityChange((newIsVisible) => {
|
||||
// if (isVisible === newIsVisible) {
|
||||
// return;
|
||||
// }
|
||||
// isVisible = newIsVisible;
|
||||
// if (isVisible) {
|
||||
// alert(nls.localize('suggestWidgetAriaVisible', "Suggestions opened"));
|
||||
// } else {
|
||||
// alert(nls.localize('suggestWidgetAriaInvisible', "Suggestions closed"));
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
private onCursorSelectionChanged(): void {
|
||||
@@ -499,11 +493,11 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
|
||||
return;
|
||||
}
|
||||
|
||||
this.editorBlurTimeout = TPromise.timeout(150).then(() => {
|
||||
if (!this.editor.isFocused()) {
|
||||
this.editorBlurTimeout.cancelAndSet(() => {
|
||||
if (!this.editor.hasTextFocus()) {
|
||||
this.setState(State.Hidden);
|
||||
}
|
||||
});
|
||||
}, 150);
|
||||
}
|
||||
|
||||
private onEditorLayoutChange(): void {
|
||||
@@ -519,7 +513,7 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
|
||||
|
||||
const item = e.elements[0];
|
||||
const index = e.indexes[0];
|
||||
item.resolve().then(() => {
|
||||
item.resolve(CancellationToken.None).then(() => {
|
||||
this.onDidSelectEmitter.fire({ item, index, model: this.completionModel });
|
||||
alert(nls.localize('suggestionAriaAccepted', "{0}, accepted", item.suggestion.label));
|
||||
this.editor.focus();
|
||||
@@ -585,6 +579,7 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
|
||||
const item = e.elements[0];
|
||||
this._ariaAlert(this._getSuggestionAriaAlertLabel(item));
|
||||
|
||||
this.firstFocusInCurrentList = !this.focusedItem;
|
||||
if (item === this.focusedItem) {
|
||||
return;
|
||||
}
|
||||
@@ -602,22 +597,25 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
|
||||
|
||||
this.list.reveal(index);
|
||||
|
||||
this.currentSuggestionDetails = item.resolve()
|
||||
.then(() => {
|
||||
// item can have extra information, so re-render
|
||||
this.ignoreFocusEvents = true;
|
||||
this.list.splice(index, 1, [item]);
|
||||
this.list.setFocus([index]);
|
||||
this.ignoreFocusEvents = false;
|
||||
this.currentSuggestionDetails = createCancelablePromise(token => item.resolve(token));
|
||||
|
||||
if (this.expandDocsSettingFromStorage()) {
|
||||
this.showDetails();
|
||||
} else {
|
||||
removeClass(this.element, 'docs-side');
|
||||
}
|
||||
})
|
||||
.then(null, err => !isPromiseCanceledError(err) && onUnexpectedError(err))
|
||||
.then(() => this.currentSuggestionDetails = null);
|
||||
this.currentSuggestionDetails.then(() => {
|
||||
// item can have extra information, so re-render
|
||||
this.ignoreFocusEvents = true;
|
||||
this.list.splice(index, 1, [item]);
|
||||
this.list.setFocus([index]);
|
||||
this.ignoreFocusEvents = false;
|
||||
|
||||
if (this.expandDocsSettingFromStorage()) {
|
||||
this.showDetails();
|
||||
} else {
|
||||
removeClass(this.element, 'docs-side');
|
||||
}
|
||||
}).catch(onUnexpectedError).then(() => {
|
||||
if (this.focusedItem === item) {
|
||||
this.currentSuggestionDetails = null;
|
||||
}
|
||||
});
|
||||
|
||||
// emit an event
|
||||
this.onDidFocusEmitter.fire({ item, index, model: this.completionModel });
|
||||
@@ -641,6 +639,7 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
|
||||
if (stateChanged) {
|
||||
this.list.splice(0, this.list.length);
|
||||
}
|
||||
this.focusedItem = null;
|
||||
break;
|
||||
case State.Loading:
|
||||
this.messageElement.textContent = SuggestWidget.LOADING_MESSAGE;
|
||||
@@ -648,6 +647,7 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
|
||||
show(this.messageElement);
|
||||
removeClass(this.element, 'docs-side');
|
||||
this.show();
|
||||
this.focusedItem = null;
|
||||
break;
|
||||
case State.Empty:
|
||||
this.messageElement.textContent = SuggestWidget.NO_SUGGESTIONS_MESSAGE;
|
||||
@@ -655,9 +655,10 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
|
||||
show(this.messageElement);
|
||||
removeClass(this.element, 'docs-side');
|
||||
this.show();
|
||||
this.focusedItem = null;
|
||||
break;
|
||||
case State.Open:
|
||||
hide(this.messageElement, this.details.element);
|
||||
hide(this.messageElement);
|
||||
show(this.listElement);
|
||||
this.show();
|
||||
break;
|
||||
@@ -696,7 +697,9 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
|
||||
this.loadingTimeout = null;
|
||||
}
|
||||
|
||||
this.completionModel = completionModel;
|
||||
if (this.completionModel !== completionModel) {
|
||||
this.completionModel = completionModel;
|
||||
}
|
||||
|
||||
if (isFrozen && this.state !== State.Empty && this.state !== State.Hidden) {
|
||||
this.setState(State.Frozen);
|
||||
@@ -731,7 +734,6 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
|
||||
*/
|
||||
this.telemetryService.publicLog('suggestWidget', { ...stats, ...this.editor.getTelemetryData() });
|
||||
|
||||
this.focusedItem = null;
|
||||
this.list.splice(0, this.list.length, this.completionModel.items);
|
||||
|
||||
if (isFrozen) {
|
||||
@@ -890,7 +892,7 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
|
||||
*/
|
||||
this.telemetryService.publicLog('suggestWidget:collapseDetails', this.editor.getTelemetryData());
|
||||
} else {
|
||||
if (this.state !== State.Open && this.state !== State.Details) {
|
||||
if (this.state !== State.Open && this.state !== State.Details && this.state !== State.Frozen) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -937,10 +939,10 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
|
||||
|
||||
this.suggestWidgetVisible.set(true);
|
||||
|
||||
this.showTimeout = TPromise.timeout(100).then(() => {
|
||||
this.showTimeout.cancelAndSet(() => {
|
||||
addClass(this.element, 'visible');
|
||||
this.onDidShowEmitter.fire(this);
|
||||
});
|
||||
}, 100);
|
||||
}
|
||||
|
||||
private hide(): void {
|
||||
@@ -1021,11 +1023,17 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
|
||||
}
|
||||
|
||||
private expandSideOrBelow() {
|
||||
if (!canExpandCompletionItem(this.focusedItem) && this.firstFocusInCurrentList) {
|
||||
removeClass(this.element, 'docs-side');
|
||||
removeClass(this.element, 'docs-below');
|
||||
return;
|
||||
}
|
||||
|
||||
let matches = this.element.style.maxWidth.match(/(\d+)px/);
|
||||
if (!matches || Number(matches[1]) < this.maxWidgetWidth) {
|
||||
addClass(this.element, 'docs-below');
|
||||
removeClass(this.element, 'docs-side');
|
||||
} else {
|
||||
} else if (canExpandCompletionItem(this.focusedItem)) {
|
||||
addClass(this.element, 'docs-side');
|
||||
removeClass(this.element, 'docs-below');
|
||||
}
|
||||
@@ -1088,15 +1096,8 @@ export class SuggestWidget implements IContentWidget, IDelegate<ICompletionItem>
|
||||
this.loadingTimeout = null;
|
||||
}
|
||||
|
||||
if (this.editorBlurTimeout) {
|
||||
this.editorBlurTimeout.cancel();
|
||||
this.editorBlurTimeout = null;
|
||||
}
|
||||
|
||||
if (this.showTimeout) {
|
||||
this.showTimeout.cancel();
|
||||
this.showTimeout = null;
|
||||
}
|
||||
this.editorBlurTimeout.dispose();
|
||||
this.showTimeout.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { ISuggestion, ISuggestResult, ISuggestSupport, SuggestionType } from 'vs/editor/common/modes';
|
||||
import { ISuggestionItem, getSuggestionComparator } from 'vs/editor/contrib/suggest/suggest';
|
||||
import { CompletionModel } from 'vs/editor/contrib/suggest/completionModel';
|
||||
import { IPosition } from 'vs/editor/common/core/position';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IPosition } from 'vs/editor/common/core/position';
|
||||
import { ISuggestResult, ISuggestSupport, ISuggestion, SuggestionType } from 'vs/editor/common/modes';
|
||||
import { CompletionModel } from 'vs/editor/contrib/suggest/completionModel';
|
||||
import { ISuggestionItem, getSuggestionComparator } from 'vs/editor/contrib/suggest/suggest';
|
||||
|
||||
export function createSuggestItem(label: string, overwriteBefore: number, type: SuggestionType = 'property', incomplete: boolean = false, position: IPosition = { lineNumber: 1, column: 1 }): ISuggestionItem {
|
||||
|
||||
@@ -77,7 +77,7 @@ suite('CompletionModel', function () {
|
||||
|
||||
test('complete/incomplete', function () {
|
||||
|
||||
assert.equal(model.incomplete, false);
|
||||
assert.equal(model.incomplete.size, 0);
|
||||
|
||||
let incompleteModel = new CompletionModel([
|
||||
createSuggestItem('foo', 3, undefined, true),
|
||||
@@ -86,7 +86,7 @@ suite('CompletionModel', function () {
|
||||
leadingLineContent: 'foo',
|
||||
characterCountDelta: 0
|
||||
});
|
||||
assert.equal(incompleteModel.incomplete, true);
|
||||
assert.equal(incompleteModel.incomplete.size, 1);
|
||||
});
|
||||
|
||||
test('replaceIncomplete', function () {
|
||||
@@ -95,17 +95,47 @@ suite('CompletionModel', function () {
|
||||
const incompleteItem = createSuggestItem('foofoo', 1, undefined, true, { lineNumber: 1, column: 2 });
|
||||
|
||||
const model = new CompletionModel([completeItem, incompleteItem], 2, { leadingLineContent: 'f', characterCountDelta: 0 });
|
||||
assert.equal(model.incomplete, true);
|
||||
assert.equal(model.incomplete.size, 1);
|
||||
assert.equal(model.items.length, 2);
|
||||
|
||||
const { complete, incomplete } = model.resolveIncompleteInfo();
|
||||
const { incomplete } = model;
|
||||
const complete = model.adopt(incomplete);
|
||||
|
||||
assert.equal(incomplete.length, 1);
|
||||
assert.ok(incomplete[0] === incompleteItem.support);
|
||||
assert.equal(incomplete.size, 1);
|
||||
assert.ok(incomplete.has(incompleteItem.support));
|
||||
assert.equal(complete.length, 1);
|
||||
assert.ok(complete[0] === completeItem);
|
||||
});
|
||||
|
||||
test('Fuzzy matching of snippets stopped working with inline snippet suggestions #49895', function () {
|
||||
const completeItem1 = createSuggestItem('foobar1', 1, undefined, false, { lineNumber: 1, column: 2 });
|
||||
const completeItem2 = createSuggestItem('foobar2', 1, undefined, false, { lineNumber: 1, column: 2 });
|
||||
const completeItem3 = createSuggestItem('foobar3', 1, undefined, false, { lineNumber: 1, column: 2 });
|
||||
const completeItem4 = createSuggestItem('foobar4', 1, undefined, false, { lineNumber: 1, column: 2 });
|
||||
const completeItem5 = createSuggestItem('foobar5', 1, undefined, false, { lineNumber: 1, column: 2 });
|
||||
const incompleteItem1 = createSuggestItem('foofoo1', 1, undefined, true, { lineNumber: 1, column: 2 });
|
||||
|
||||
const model = new CompletionModel(
|
||||
[
|
||||
completeItem1,
|
||||
completeItem2,
|
||||
completeItem3,
|
||||
completeItem4,
|
||||
completeItem5,
|
||||
incompleteItem1,
|
||||
], 2, { leadingLineContent: 'f', characterCountDelta: 0 }
|
||||
);
|
||||
assert.equal(model.incomplete.size, 1);
|
||||
assert.equal(model.items.length, 6);
|
||||
|
||||
const { incomplete } = model;
|
||||
const complete = model.adopt(incomplete);
|
||||
|
||||
assert.equal(incomplete.size, 1);
|
||||
assert.ok(incomplete.has(incompleteItem1.support));
|
||||
assert.equal(complete.length, 5);
|
||||
});
|
||||
|
||||
test('proper current word when length=0, #16380', function () {
|
||||
|
||||
model = new CompletionModel([
|
||||
@@ -137,7 +167,7 @@ suite('CompletionModel', function () {
|
||||
], 1, {
|
||||
leadingLineContent: 's',
|
||||
characterCountDelta: 0
|
||||
}, 'top');
|
||||
}, { snippets: 'top', snippetsPreventQuickSuggestions: true, filterGraceful: true });
|
||||
|
||||
assert.equal(model.items.length, 2);
|
||||
const [a, b] = model.items;
|
||||
@@ -156,7 +186,7 @@ suite('CompletionModel', function () {
|
||||
], 1, {
|
||||
leadingLineContent: 's',
|
||||
characterCountDelta: 0
|
||||
}, 'bottom');
|
||||
}, { snippets: 'bottom', snippetsPreventQuickSuggestions: true, filterGraceful: true });
|
||||
|
||||
assert.equal(model.items.length, 2);
|
||||
const [a, b] = model.items;
|
||||
@@ -174,7 +204,7 @@ suite('CompletionModel', function () {
|
||||
], 1, {
|
||||
leadingLineContent: 's',
|
||||
characterCountDelta: 0
|
||||
}, 'inline');
|
||||
}, { snippets: 'inline', snippetsPreventQuickSuggestions: true, filterGraceful: true });
|
||||
|
||||
assert.equal(model.items.length, 2);
|
||||
const [a, b] = model.items;
|
||||
@@ -237,7 +267,7 @@ suite('CompletionModel', function () {
|
||||
], 1, {
|
||||
leadingLineContent: '',
|
||||
characterCountDelta: 0
|
||||
}, 'inline');
|
||||
});
|
||||
|
||||
assert.equal(model.items.length, 5);
|
||||
|
||||
@@ -264,7 +294,7 @@ suite('CompletionModel', function () {
|
||||
], 1, {
|
||||
leadingLineContent: '',
|
||||
characterCountDelta: 0
|
||||
}, 'inline');
|
||||
});
|
||||
|
||||
// query gets longer, narrow down the narrow-down'ed-set from before
|
||||
model.lineContext = { leadingLineContent: 'rlut', characterCountDelta: 4 };
|
||||
@@ -286,7 +316,7 @@ suite('CompletionModel', function () {
|
||||
], 1, {
|
||||
leadingLineContent: '',
|
||||
characterCountDelta: 0
|
||||
}, 'inline');
|
||||
});
|
||||
|
||||
model.lineContext = { leadingLineContent: 'form', characterCountDelta: 4 };
|
||||
assert.equal(model.items.length, 5);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { LRUMemory, NoMemory, PrefixMemory } from 'vs/editor/contrib/suggest/suggestMemory';
|
||||
import { LRUMemory, NoMemory, PrefixMemory, Memory } from 'vs/editor/contrib/suggest/suggestMemory';
|
||||
import { ITextModel } from 'vs/editor/common/model';
|
||||
import { TextModel } from 'vs/editor/common/model/textModel';
|
||||
import { ICompletionItem } from 'vs/editor/contrib/suggest/completionModel';
|
||||
@@ -28,6 +28,46 @@ suite('SuggestMemories', function () {
|
||||
];
|
||||
});
|
||||
|
||||
test('AbstractMemory, select', function () {
|
||||
|
||||
const mem = new class extends Memory {
|
||||
memorize(model: ITextModel, pos: IPosition, item: ICompletionItem): void {
|
||||
throw new Error('Method not implemented.');
|
||||
} toJSON(): object {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
fromJSON(data: object): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
};
|
||||
|
||||
let item1 = createSuggestItem('fazz', 0);
|
||||
let item2 = createSuggestItem('bazz', 0);
|
||||
let item3 = createSuggestItem('bazz', 0);
|
||||
let item4 = createSuggestItem('bazz', 0);
|
||||
item1.suggestion.preselect = false;
|
||||
item2.suggestion.preselect = true;
|
||||
item3.suggestion.preselect = true;
|
||||
|
||||
assert.equal(mem.select(buffer, pos, [item1, item2, item3, item4]), 1);
|
||||
});
|
||||
|
||||
test('[No|Prefix|LRU]Memory honor selection boost', function () {
|
||||
let item1 = createSuggestItem('fazz', 0);
|
||||
let item2 = createSuggestItem('bazz', 0);
|
||||
let item3 = createSuggestItem('bazz', 0);
|
||||
let item4 = createSuggestItem('bazz', 0);
|
||||
item1.suggestion.preselect = false;
|
||||
item2.suggestion.preselect = true;
|
||||
item3.suggestion.preselect = true;
|
||||
let items = [item1, item2, item3, item4];
|
||||
|
||||
|
||||
assert.equal(new NoMemory().select(buffer, pos, items), 1);
|
||||
assert.equal(new LRUMemory().select(buffer, pos, items), 1);
|
||||
assert.equal(new PrefixMemory().select(buffer, pos, items), 1);
|
||||
});
|
||||
|
||||
test('NoMemory', function () {
|
||||
|
||||
const mem = new NoMemory();
|
||||
|
||||
@@ -6,47 +6,38 @@
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { IDisposable, dispose, Disposable } from 'vs/base/common/lifecycle';
|
||||
import { TextModel } from 'vs/editor/common/model/textModel';
|
||||
import { Handler } from 'vs/editor/common/editorCommon';
|
||||
import { ISuggestSupport, ISuggestResult, SuggestRegistry, SuggestTriggerKind, LanguageIdentifier, TokenizationRegistry, IState, MetadataConsts } from 'vs/editor/common/modes';
|
||||
import { SuggestModel, LineContext } from 'vs/editor/contrib/suggest/suggestModel';
|
||||
import { TestCodeEditor, MockScopeLocation } from 'vs/editor/test/browser/testCodeEditor';
|
||||
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
|
||||
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
|
||||
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { MockContextKeyService } from 'vs/platform/keybinding/test/common/mockKeybindingService';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
|
||||
import { CoreEditingCommands } from 'vs/editor/browser/controller/coreCommands';
|
||||
import { EditOperation } from 'vs/editor/common/core/editOperation';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { Selection } from 'vs/editor/common/core/selection';
|
||||
import { CoreEditingCommands } from 'vs/editor/browser/controller/coreCommands';
|
||||
import { SuggestController } from 'vs/editor/contrib/suggest/suggestController';
|
||||
import { IStorageService, NullStorageService } from 'vs/platform/storage/common/storage';
|
||||
import { SnippetController2 } from 'vs/editor/contrib/snippet/snippetController2';
|
||||
import { ISelectedSuggestion } from 'vs/editor/contrib/suggest/suggestWidget';
|
||||
import { MockMode } from 'vs/editor/test/common/mocks/mockMode';
|
||||
import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
|
||||
import { TokenizationResult2 } from 'vs/editor/common/core/token';
|
||||
import { Handler } from 'vs/editor/common/editorCommon';
|
||||
import { TextModel } from 'vs/editor/common/model/textModel';
|
||||
import { IState, ISuggestResult, ISuggestSupport, LanguageIdentifier, MetadataConsts, SuggestRegistry, SuggestTriggerKind, TokenizationRegistry } from 'vs/editor/common/modes';
|
||||
import { LanguageConfigurationRegistry } from 'vs/editor/common/modes/languageConfigurationRegistry';
|
||||
import { NULL_STATE } from 'vs/editor/common/modes/nullMode';
|
||||
import { TestNotificationService } from 'vs/platform/notification/test/common/testNotificationService';
|
||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||
import { SnippetController2 } from 'vs/editor/contrib/snippet/snippetController2';
|
||||
import { SuggestController } from 'vs/editor/contrib/suggest/suggestController';
|
||||
import { LineContext, SuggestModel } from 'vs/editor/contrib/suggest/suggestModel';
|
||||
import { ISelectedSuggestion } from 'vs/editor/contrib/suggest/suggestWidget';
|
||||
import { TestCodeEditor, createTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
|
||||
import { MockMode } from 'vs/editor/test/common/mocks/mockMode';
|
||||
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
|
||||
import { IStorageService, NullStorageService } from 'vs/platform/storage/common/storage';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
|
||||
|
||||
function createMockEditor(model: TextModel): TestCodeEditor {
|
||||
const contextKeyService = new MockContextKeyService();
|
||||
const telemetryService = NullTelemetryService;
|
||||
const notificationService = new TestNotificationService();
|
||||
const instantiationService = new InstantiationService(new ServiceCollection(
|
||||
[IContextKeyService, contextKeyService],
|
||||
[ITelemetryService, telemetryService],
|
||||
[IStorageService, NullStorageService],
|
||||
[INotificationService, TestNotificationService]
|
||||
));
|
||||
|
||||
const editor = new TestCodeEditor(new MockScopeLocation(), {}, false, instantiationService, contextKeyService, notificationService);
|
||||
editor.setModel(model);
|
||||
let editor = createTestCodeEditor({
|
||||
model: model,
|
||||
serviceCollection: new ServiceCollection(
|
||||
[ITelemetryService, NullTelemetryService],
|
||||
[IStorageService, NullStorageService]
|
||||
),
|
||||
});
|
||||
editor.registerAndInstantiateContribution(SnippetController2);
|
||||
return editor;
|
||||
}
|
||||
|
||||
@@ -474,7 +465,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
||||
model.trigger({ auto: false });
|
||||
}, event => {
|
||||
assert.equal(event.auto, false);
|
||||
assert.equal(event.completionModel.incomplete, true);
|
||||
assert.equal(event.completionModel.incomplete.size, 1);
|
||||
assert.equal(event.completionModel.items.length, 1);
|
||||
|
||||
return assertEvent(model.onDidCancel, () => {
|
||||
@@ -511,7 +502,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
||||
model.trigger({ auto: false });
|
||||
}, event => {
|
||||
assert.equal(event.auto, false);
|
||||
assert.equal(event.completionModel.incomplete, true);
|
||||
assert.equal(event.completionModel.incomplete.size, 1);
|
||||
assert.equal(event.completionModel.items.length, 1);
|
||||
|
||||
return assertEvent(model.onDidSuggest, () => {
|
||||
@@ -521,7 +512,7 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
||||
editor.trigger('keyboard', Handler.Type, { text: ';' });
|
||||
}, event => {
|
||||
assert.equal(event.auto, false);
|
||||
assert.equal(event.completionModel.incomplete, true);
|
||||
assert.equal(event.completionModel.incomplete.size, 1);
|
||||
assert.equal(event.completionModel.items.length, 1);
|
||||
|
||||
});
|
||||
@@ -703,4 +694,57 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('Fails to render completion details #47988', function () {
|
||||
|
||||
let disposeA = 0;
|
||||
let disposeB = 0;
|
||||
|
||||
disposables.push(SuggestRegistry.register({ scheme: 'test' }, {
|
||||
provideCompletionItems(doc, pos) {
|
||||
return {
|
||||
incomplete: true,
|
||||
suggestions: [{ type: 'folder', label: 'CompleteNot', insertText: 'Incomplete', sortText: 'a', overwriteBefore: pos.column - 1 }],
|
||||
dispose() { disposeA += 1; }
|
||||
};
|
||||
}
|
||||
}));
|
||||
disposables.push(SuggestRegistry.register({ scheme: 'test' }, {
|
||||
provideCompletionItems(doc, pos) {
|
||||
return {
|
||||
incomplete: false,
|
||||
suggestions: [{ type: 'folder', label: 'Complete', insertText: 'Complete', sortText: 'z', overwriteBefore: pos.column - 1 }],
|
||||
dispose() { disposeB += 1; }
|
||||
};
|
||||
},
|
||||
resolveCompletionItem(doc, pos, item) {
|
||||
return item;
|
||||
},
|
||||
}));
|
||||
|
||||
return withOracle(async (model, editor) => {
|
||||
|
||||
await assertEvent(model.onDidSuggest, () => {
|
||||
editor.setValue('');
|
||||
editor.setSelection(new Selection(1, 1, 1, 1));
|
||||
editor.trigger('keyboard', Handler.Type, { text: 'c' });
|
||||
|
||||
}, event => {
|
||||
assert.equal(event.auto, true);
|
||||
assert.equal(event.completionModel.items.length, 2);
|
||||
assert.equal(disposeA, 0);
|
||||
assert.equal(disposeB, 0);
|
||||
});
|
||||
|
||||
await assertEvent(model.onDidSuggest, () => {
|
||||
editor.trigger('keyboard', Handler.Type, { text: 'o' });
|
||||
}, event => {
|
||||
assert.equal(event.auto, true);
|
||||
assert.equal(event.completionModel.items.length, 2);
|
||||
assert.equal(disposeA, 1);
|
||||
assert.equal(disposeB, 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user