feat: Use the editor language when none is specified
What does this merge request do and why?
Unsaved files may not have a filename yet, but the user may have already chosen a language within the editor. Default to the editor's language if we haven't guessed a language from the extension.
How to set up and validate locally
- Patch the VSCode extensions to use the local server:
diff --git a/src/common/code_suggestions/code_suggestions_provider.ts b/src/common/code_suggestions/code_suggestions_provider.ts
index 5bca652f..d4e80e9e 100644
--- a/src/common/code_suggestions/code_suggestions_provider.ts
+++ b/src/common/code_suggestions/code_suggestions_provider.ts
@@ -241,10 +241,7 @@ export class CodeSuggestionsProvider implements vscode.InlineCompletionItemProvi
let model: Model = { engine: '', name: '', lang: '' }; // Defaults for telemetry of failed requests
let experiments: Experiment[] = [];
- const gitlabMonolithApiAvailable =
- !this.legacyApiFallbackConfig.shouldUseModelGateway() ||
- isEnabled(FeatureFlag.ForceCodeSuggestionsViaMonolith);
-
+ const gitlabMonolithApiAvailable = false;
try {
this.stateManager.setTemporaryState(TemporaryCodeSuggestionsState.LOADING);
if (gitlabMonolithApiAvailable) {
diff --git a/src/common/code_suggestions/constants.ts b/src/common/code_suggestions/constants.ts
index a7cae242..57f4351d 100644
--- a/src/common/code_suggestions/constants.ts
+++ b/src/common/code_suggestions/constants.ts
@@ -1,5 +1,5 @@
export const MODEL_GATEWAY_AI_ASSISTED_CODE_SUGGESTIONS_API_URL =
- 'https://codesuggestions.gitlab.com/v2/completions';
+ 'http://localhost:9999/v2/completions';
export const GITLAB_AI_ASSISTED_CODE_SUGGESTIONS_API_PATH = '/code_suggestions/completions';
export const AI_ASSISTED_CODE_SUGGESTIONS_CONFIG_NAMESPACE = 'gitlab.aiAssistedCodeSuggestions';
export const NEW_CODE_SUGGESTION_GITLAB_RELEASE = '16.3.0';
- Build a
.vsix
file:
npm install
npm run clean
npm run package
-
Install the
.vsix
file in VSCode and restart VSCode. -
In VSCode, in a GitLab project, create a new file and click
Select a language
:
-
Choose a language (e.g. such as
cpp
), and start writing code. -
Run
curl http://localhost:8082
to see the metrics:
% curl -s http://localhost:8082 | grep lang
# HELP code_suggestions_prompt_language_total Language count by number
# TYPE code_suggestions_prompt_language_total counter
code_suggestions_prompt_language_total{editor_lang="cpp",extension="",lang="None"} 1.0
# HELP code_suggestions_prompt_language_created Language count by number
# TYPE code_suggestions_prompt_language_created gauge
code_suggestions_prompt_language_created{editor_lang="cpp",extension="",lang="None"} 1.694063670484713e+09
code_suggestions_prompt_symbols_total{lang="cpp",symbol="comment"} 1.0
code_suggestions_prompt_symbols_total{lang="cpp",symbol="preproc_include"} 1.0
code_suggestions_prompt_symbols_created{lang="cpp",symbol="comment"} 1.694063670518974e+09
code_suggestions_prompt_symbols_created{lang="cpp",symbol="preproc_include"} 1.6940636705189838e+09
Merge request checklist
-
Tests added for new functionality. If not, please raise an issue to follow up. -
Documentation added/updated, if needed.
Edited by Stan Hu