Skip to content

Commit

Permalink
Improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
arshad-yaseen committed Jun 9, 2024
1 parent 25a906a commit 05a17a5
Show file tree
Hide file tree
Showing 20 changed files with 51 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/classes/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {DEFAULT_COMPLETION_MODEL} from '../constants/completion';
import {CompletionModel} from '../types/completion';
import type {CompletionModel} from '../types/completion';

/**
* Configuration class to store the following:
Expand Down
2 changes: 1 addition & 1 deletion src/classes/copilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
GROQ_API_ENDPOINT,
} from '../constants/completion';
import {generateSystemPrompt, generateUserPrompt} from '../helpers/prompt';
import {
import type {
CompletionRequest,
CompletionResponse,
GroqCompletion,
Expand Down
2 changes: 1 addition & 1 deletion src/classes/local-code-prediction-engine.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import predictions from '../helpers/local-prediction';
import {LocalPredictionSnippets} from '../types/completion';
import type {LocalPredictionSnippets} from '../types/completion';

export class LocalCodePredictionEngine {
private predictions: Map<string, LocalPredictionSnippets>;
Expand Down
2 changes: 1 addition & 1 deletion src/constants/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {EditorBuiltInTheme, EditorOptions} from '../types/common';
import type {EditorBuiltInTheme, EditorOptions} from '../types/common';

export const EDITOR_DEFAULT_OPTIONS: EditorOptions = {
scrollBeyondLastColumn: 0,
Expand Down
2 changes: 1 addition & 1 deletion src/constants/completion.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CompletionModel} from '../types/completion';
import type {CompletionModel} from '../types/completion';

export const COMPLETION_MODEL_IDS: Record<CompletionModel, string> = {
llama: 'llama3-70b-8192',
Expand Down
4 changes: 2 additions & 2 deletions src/editor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import {Monaco, Editor as MonacoEditor} from '@monaco-editor/react';
import {Editor as MonacoEditor, type Monaco} from '@monaco-editor/react';

import {
EDITOR_BUILT_IN_THEMES,
Expand All @@ -13,7 +13,7 @@ import type {
EditorOptions,
StandaloneCodeEditor,
} from './types/common';
import EditorProps from './types/editor-props';
import type EditorProps from './types/editor-props';
import {deepMerge} from './utils/common';

const Editor = ({
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/contextual-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
FILTER_LANGUAGE_MAP,
FILTER_WEIGHTS,
} from '../constants/contextual-filter';
import {ContextualFilterContext} from '../types/completion';
import type {ContextualFilterContext} from '../types/completion';
import {getLastLineLength} from '../utils/completion/common';

class ContextualFilterManager {
Expand Down
9 changes: 3 additions & 6 deletions src/helpers/get-completion.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import {
EditorModel,
EditorPosition,
FetchCompletionItemParams,
} from '../types/common';
import {
import type {EditorModel, EditorPosition} from '../types/common';
import type {
CompletionMetadata,
CompletionRequest,
CompletionResponse,
FetchCompletionItemParams,
} from '../types/completion';
import {
determineCompletionMode,
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/local-prediction/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {LocalPrediction} from '../../types/completion';
import type {LocalPrediction} from '../../types/completion';
import javascript from './javascript';

export default [
Expand Down
3 changes: 3 additions & 0 deletions src/helpers/local-prediction/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ export default {
'async (': ') => {\n\t$1\n}$0',
'async =>': ' {\n\t$1\n}$0',
') =>': ' {',
'=>': ' {',
'new M': 'ap',
'new W': 'eakMap',
};
4 changes: 2 additions & 2 deletions src/helpers/prompt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {CompletionMetadata, CompletionMode} from '../types/completion';
import {Technologies} from '../types/editor-props';
import type {CompletionMetadata, CompletionMode} from '../types/completion';
import type {Technologies} from '../types/editor-props';
import {joinWithAnd} from '../utils/common';

const CURSOR_PLACEHOLDER = '<<CURSOR>>';
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/use-start-completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
computeCompletionCacheKey,
fetchCompletionItem,
} from '../helpers/get-completion';
import {EditorInlineCompletion} from '../types/common';
import {
import type {EditorInlineCompletion} from '../types/common';
import type {
CompletionSpeed,
Endpoint,
ExternalContext,
Expand Down
2 changes: 1 addition & 1 deletion src/themes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {EditorThemeData} from './types/common';
import type {EditorThemeData} from './types/common';

interface CustomThemeCollection {
[key: string]: EditorThemeData;
Expand Down
20 changes: 1 addition & 19 deletions src/types/common.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import {Theme} from '@monaco-editor/react';
import * as monaco from 'monaco-editor';

import {
Endpoint,
ExternalContext,
Filename,
Technologies,
} from './editor-props';

export type EditorOptions = monaco.editor.IEditorOptions;
export type StandaloneCodeEditor = monaco.editor.IStandaloneCodeEditor;
export type EditorModel = monaco.editor.ITextModel;
Expand All @@ -16,15 +9,4 @@ export type EditorRange = monaco.IRange;
export type EditorInlineCompletion = monaco.languages.InlineCompletion;
export type EditorThemeData = monaco.editor.IStandaloneThemeData;
export type EditorBuiltInTheme = Theme;

export interface FetchCompletionItemParams {
code: string;
language: string;
endpoint: Endpoint;
filename: Filename | undefined;
technologies: Technologies | undefined;
externalContext: ExternalContext | undefined;
model: EditorModel;
position: EditorPosition;
token: monaco.CancellationToken;
}
export type EditorCompletionCancellationToken = monaco.CancellationToken;
26 changes: 24 additions & 2 deletions src/types/completion.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import {
import type {
ChatCompletion,
ChatCompletionCreateParamsBase,
} from 'groq-sdk/resources/chat/completions';

import {ExternalContext, Filename, Technologies} from './editor-props';
import type {
EditorCompletionCancellationToken,
EditorModel,
EditorPosition,
} from './common';
import type {
Endpoint,
ExternalContext,
Filename,
Technologies,
} from './editor-props';

export type CompletionModel = 'llama';

Expand Down Expand Up @@ -49,3 +59,15 @@ export interface ContextualFilterContext {
};
prefix?: string;
}

export interface FetchCompletionItemParams {
code: string;
language: string;
endpoint: Endpoint;
filename: Filename | undefined;
technologies: Technologies | undefined;
externalContext: ExternalContext | undefined;
model: EditorModel;
position: EditorPosition;
token: EditorCompletionCancellationToken;
}
2 changes: 1 addition & 1 deletion src/types/copilot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CompletionModel} from './completion';
import type {CompletionModel} from './completion';

export interface CopilotOptions {
model: CompletionModel | undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/types/editor-props.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {EditorProps as MonacoEditorProps} from '@monaco-editor/react';

import {EditorBuiltInTheme} from './common';
import type {EditorBuiltInTheme} from './common';

/**
* Themes available for the Monacopilot
Expand Down
2 changes: 1 addition & 1 deletion src/utils/completion/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {EditorPosition} from '../../types/common';
import type {EditorPosition} from '../../types/common';

export const getCharAtPosition = (line: string, position: number) =>
line[position] || '';
Expand Down
4 changes: 2 additions & 2 deletions src/utils/completion/syntax-parser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {EditorModel, EditorPosition} from '../../types/common';
import {CompletionMode} from '../../types/completion';
import type {EditorModel, EditorPosition} from '../../types/common';
import type {CompletionMode} from '../../types/completion';
import {getCharAtPosition} from './common';

export const isAfterCursorWhitespace = (
Expand Down
2 changes: 1 addition & 1 deletion src/utils/completion/validate-completion.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {CONTEXTUAL_FILTER_ACCEPT_THRESHOLD} from '../../constants/contextual-filter';
import {getContextualFilterScore} from '../../helpers/contextual-filter';
import {EditorModel, EditorPosition} from '../../types/common';
import type {EditorModel, EditorPosition} from '../../types/common';
import {
getCodeBeforeAndAfterCursor,
isAfterCursorWhitespace,
Expand Down

0 comments on commit 05a17a5

Please sign in to comment.