mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 09:17:53 +00:00
Fix(command): line/block Comments Incorrectly Parsed as Slash Commands (#6957)
Co-authored-by: Abhi <43648792+abhipatel12@users.noreply.github.com>
This commit is contained in:
@@ -102,6 +102,20 @@ describe('commandUtils', () => {
|
||||
expect(isSlashCommand('path/to/file')).toBe(false);
|
||||
expect(isSlashCommand(' /help')).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false for line comments starting with //', () => {
|
||||
expect(isSlashCommand('// This is a comment')).toBe(false);
|
||||
expect(isSlashCommand('// check if variants base info all filled.')).toBe(
|
||||
false,
|
||||
);
|
||||
expect(isSlashCommand('//comment without space')).toBe(false);
|
||||
});
|
||||
|
||||
it('should return false for block comments starting with /*', () => {
|
||||
expect(isSlashCommand('/* This is a block comment */')).toBe(false);
|
||||
expect(isSlashCommand('/*\n * Multi-line comment\n */')).toBe(false);
|
||||
expect(isSlashCommand('/*comment without space*/')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('copyToClipboard', () => {
|
||||
|
||||
@@ -21,12 +21,28 @@ export const isAtCommand = (query: string): boolean =>
|
||||
|
||||
/**
|
||||
* Checks if a query string potentially represents an '/' command.
|
||||
* It triggers if the query starts with '/'
|
||||
* It triggers if the query starts with '/' but excludes code comments like '//' and '/*'.
|
||||
*
|
||||
* @param query The input query string.
|
||||
* @returns True if the query looks like an '/' command, false otherwise.
|
||||
*/
|
||||
export const isSlashCommand = (query: string): boolean => query.startsWith('/');
|
||||
export const isSlashCommand = (query: string): boolean => {
|
||||
if (!query.startsWith('/')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Exclude line comments that start with '//'
|
||||
if (query.startsWith('//')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Exclude block comments that start with '/*'
|
||||
if (query.startsWith('/*')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
// Copies a string snippet to the clipboard for different platforms
|
||||
export const copyToClipboard = async (text: string): Promise<void> => {
|
||||
|
||||
Reference in New Issue
Block a user