Skip to content

Commit

Permalink
Merge pull request #69 from arshad-yaseen/improve-deprecated-logging
Browse files Browse the repository at this point in the history
Improve deprecated logger
  • Loading branch information
arshad-yaseen authored Oct 27, 2024
2 parents bf08245 + ff18dd3 commit 4f67463
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
5 changes: 1 addition & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@


## [0.12.9](https://github.com/arshad-yaseen/monacopilot/compare/v0.12.8...v0.12.9) (2024-10-27)


### 📚 Documentation

* mention to always specify provider and model ([8edf342](https://github.com/arshad-yaseen/monacopilot/commit/8edf3424869a6325e2ef3a01c63ba48826180e22))
- mention to always specify provider and model ([8edf342](https://github.com/arshad-yaseen/monacopilot/commit/8edf3424869a6325e2ef3a01c63ba48826180e22))

## [0.12.8](https://github.com/arshad-yaseen/monacopilot/compare/v0.12.7...v0.12.8) (2024-10-26)

Expand Down
4 changes: 1 addition & 3 deletions src/classes/copilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ export class Copilot {
if (typeof this.model === 'object' && 'transformResponse' in this.model) {
const transformedResponse = this.model.transformResponse(chatCompletion);
if ('completion' in transformedResponse) {
deprecated(
'The `completion` property in `transformResponse` function is deprecated. Please use `text` instead.',
);
deprecated('completion', 'text', 'Copilot.model.transformResponse');
}
return {
completion:
Expand Down
4 changes: 1 addition & 3 deletions src/core/completion/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,7 @@ const handleTriggerCompletion = (editor: StandaloneCodeEditor) => {
export const registerCopilot = (
...args: Parameters<typeof registerCompletion>
) => {
deprecated(
'The `registerCopilot` function is deprecated. Use `registerCompletion` instead.',
);
deprecated('registerCopilot', 'registerCompletion');

return registerCompletion(...args);
};
14 changes: 10 additions & 4 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,20 @@ export const report = (error: unknown): {message: string; stack?: string} => {
return {message: errorMessage, stack: errorStack};
};

export const deprecated = (message: string): void => {
console.warn(`${YELLOW}${BOLD}[MONACOPILOT DEPRECATED] ${message}${RESET}`);
};

export const warn = (message: string): void => {
console.warn(`${YELLOW}${BOLD}[MONACOPILOT WARN] ${message}${RESET}`);
};

export const log = (message: string): void => {
console.log(`${BOLD}[MONACOPILOT] ${message}${RESET}`);
};

export const deprecated = (
oldFeature: string,
newFeature: string,
location?: string,
): void =>
console.warn(
`${YELLOW}${BOLD}[MONACOPILOT DEPRECATED] "${oldFeature}" is deprecated${location ? ` in ${location}` : ''}. ` +
`Please use "${newFeature}" instead. It will be removed in a future version.${RESET}`,
);
4 changes: 2 additions & 2 deletions tests/ui/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {useEffect, useState} from 'react';

import Editor from '@monaco-editor/react';
import {
registerCompletion,
registerCopilot,
type Monaco,
type StandaloneCodeEditor,
} from 'monacopilot';
Expand All @@ -16,7 +16,7 @@ export default function Home() {
useEffect(() => {
if (!monaco || !editor) return;

const completion = registerCompletion(monaco, editor, {
const completion = registerCopilot(monaco, editor, {
endpoint: '/api/complete',
language: 'javascript',
maxContextLines: 60,
Expand Down

0 comments on commit 4f67463

Please sign in to comment.