🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@fc-components/monaco-editor

Package Overview
Dependencies
Maintainers
5
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fc-components/monaco-editor - npm Package Compare versions

Comparing version
0.5.4
to
0.5.5
+76
src/promql/__tests__/getCompletionProvider.test.ts
import type * as monaco from 'monaco-editor';
import { getCompletionProvider } from '../completion/getCompletionProvider';
import type { DataProvider } from '../completion/DataProvider';
jest.mock('../completion/completions', () => ({
getCompletions: jest.fn().mockResolvedValue([
{
type: 'FUNCTION',
label: 'sum',
insertText: 'sum',
},
]),
}));
function createMockModel(value: string): monaco.editor.ITextModel {
return {
getValue: () => value,
getWordAtPosition: () => ({ word: value, startColumn: 1, endColumn: value.length + 1 }),
getValueInRange: () => value,
getOffsetAt: (position) => position.column - 1,
getPositionAt: (offset) => ({ lineNumber: 1, column: offset + 1 }),
} as unknown as monaco.editor.ITextModel;
}
function createMockDataProvider(): DataProvider {
return {
monacoSettings: {
setInputInRange: jest.fn(),
suggestionsIncomplete: false,
},
} as unknown as DataProvider;
}
const mockMonaco = {
Range: {
lift: (range: monaco.IRange) => range,
fromPositions: (position: monaco.Position) => ({
startLineNumber: position.lineNumber,
startColumn: position.column,
endLineNumber: position.lineNumber,
endColumn: position.column,
}),
},
languages: {
CompletionItemKind: {
Unit: 1,
Variable: 2,
Snippet: 3,
Enum: 4,
EnumMember: 5,
Constructor: 6,
},
},
} as unknown as typeof monaco;
describe('getCompletionProvider', () => {
it('only replaces the word prefix before the cursor', async () => {
const provider = getCompletionProvider(mockMonaco, createMockDataProvider());
const result = await provider.provideCompletionItems!(createMockModel('sucpu_usage_idle'), { lineNumber: 1, column: 3 });
expect(result).toMatchObject({
suggestions: [
{
label: 'sum',
range: {
startLineNumber: 1,
startColumn: 1,
endLineNumber: 1,
endColumn: 3,
},
command: { id: 'hideSuggestWidget' },
},
],
});
});
});
+1
-1

@@ -6,3 +6,3 @@ {

},
"version": "0.5.4",
"version": "0.5.5",
"license": "MIT",

@@ -9,0 +9,0 @@ "main": "dist/index.js",

@@ -43,3 +43,6 @@ import type * as monacoTypes from 'monaco-editor/esm/vs/editor/editor.api';

startColumn: word.startColumn,
endColumn: word.endColumn,
// Only replace the prefix that was typed before the cursor. Using
// word.endColumn here also replaces the identifier suffix when
// completion is invoked in the middle of an existing metric name.
endColumn: position.column,
})

@@ -96,8 +99,9 @@ : monaco.Range.fromPositions(position);

range: completionRange,
command: item.triggerOnInsert
? {
id: 'editor.action.triggerSuggest',
title: '',
}
: undefined,
command: {
// Label-name completions intentionally chain into the next
// completion step. All other accepted items should dismiss the
// suggest widget instead of leaving an obsolete list visible.
id: item.triggerOnInsert ? 'editor.action.triggerSuggest' : 'hideSuggestWidget',
title: '',
},
}));

@@ -104,0 +108,0 @@ return { suggestions, incomplete: dataProvider.monacoSettings.suggestionsIncomplete };

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display