From bc8a1513fa05fdb6ae7568e8a4cee28382a94063 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sun, 21 Jul 2024 07:09:13 -0700 Subject: [PATCH] Polish platform file extension boosts Fixes #222408 --- .../suggest/browser/simpleCompletionModel.ts | 48 +++++++++++++++---- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/src/vs/workbench/services/suggest/browser/simpleCompletionModel.ts b/src/vs/workbench/services/suggest/browser/simpleCompletionModel.ts index 33a694e4116..f1fda72f5e0 100644 --- a/src/vs/workbench/services/suggest/browser/simpleCompletionModel.ts +++ b/src/vs/workbench/services/suggest/browser/simpleCompletionModel.ts @@ -195,13 +195,16 @@ export class SimpleCompletionModel { if (score !== 0) { return score; } - // If they're files, boost extensions depending on the operating system - score = fileExtScore(b.fileExtLow) - fileExtScore(a.fileExtLow); - if (score !== 0) { - return score; + // If they're files at the start of the command line, boost extensions depending on the operating system + const isFileCommand = !formattedLeadingLineContent.includes(' '); + if (isFileCommand) { + score = fileExtScore(b.fileExtLow) - fileExtScore(a.fileExtLow); + if (score !== 0) { + return score; + } } // Then by file extension length ascending - score = b.fileExtLow.length - a.fileExtLow.length; + score = a.fileExtLow.length - b.fileExtLow.length; } return score; }); @@ -216,14 +219,39 @@ export class SimpleCompletionModel { } // TODO: This should be based on the process OS, not the local OS +// File score boosts for specific file extensions on Windows. This only applies when the file is the +// _first_ part of the command line. const fileExtScores = new Map(isWindows ? [ + // Pwsh ['ps1', 0.09], - ['bat', 0.08], - ['sh', -0.09] + // Windows + ['bat', 0.05], + ['cmd', 0.05], + // Non-Windows + ['sh', -0.05], + ['bash', -0.05], + ['zsh', -0.05], + ['fish', -0.05], + ['csh', -0.06], // C shell + ['ksh', -0.06], // Korn shell + // Scripting language files are excluded here as the standard behavior on Windows will just open + // the file in a text editor, not run the file ] : [ - ['ps1', 0.09], - ['bat', -0.08], - ['sh', 0.08], + // Pwsh + ['ps1', 0.05], + // Windows + ['bat', -0.05], + ['cmd', -0.05], + // Non-Windows + ['sh', 0.05], + ['bash', 0.05], + ['zsh', 0.05], + ['fish', 0.05], + ['csh', 0.04], // C shell + ['ksh', 0.04], // Korn shell + // Scripting languages + ['py', 0.05], // Python + ['pl', 0.05], // Perl ]); function fileExtScore(ext: string): number {