@@ -28,7 +28,7 @@ import * as fs from 'fs';
2828import * as os from 'os' ;
2929import { SourceFileConfiguration , SourceFileConfigurationItem , Version , WorkspaceBrowseConfiguration } from 'vscode-cpptools' ;
3030import { IntelliSenseStatus , Status } from 'vscode-cpptools/out/testApi' ;
31- import { CloseAction , ErrorAction , LanguageClientOptions , NotificationType , Position , Range , RequestType , ResponseError , TextDocumentIdentifier , TextDocumentPositionParams } from 'vscode-languageclient' ;
31+ import { CloseAction , DidOpenTextDocumentParams , ErrorAction , LanguageClientOptions , NotificationType , Position , Range , RequestType , ResponseError , TextDocumentIdentifier , TextDocumentPositionParams } from 'vscode-languageclient' ;
3232import { LanguageClient , ServerOptions } from 'vscode-languageclient/node' ;
3333import * as nls from 'vscode-nls' ;
3434import { DebugConfigurationProvider } from '../Debugger/configurationProvider' ;
@@ -517,10 +517,15 @@ interface TagParseStatus {
517517 isPaused : boolean ;
518518}
519519
520+ interface VisibleEditorInfo {
521+ visibleRanges : Range [ ] ;
522+ originalEncoding : string ;
523+ }
524+
520525interface DidChangeVisibleTextEditorsParams {
521526 activeUri ?: string ;
522527 activeSelection ?: Range ;
523- visibleRanges ?: { [ uri : string ] : Range [ ] } ;
528+ visibleEditorInfo ?: { [ uri : string ] : VisibleEditorInfo } ;
524529}
525530
526531interface DidChangeTextEditorVisibleRangesParams {
@@ -590,18 +595,11 @@ export interface CopilotCompletionContextParams {
590595 doAggregateSnippets : boolean ;
591596}
592597
593- export interface TextDocumentItemWithOriginalEncoding {
598+ export interface SetOpenFileOriginalEncodingParams {
594599 uri : string ;
595- languageId : string ;
596- version : number ;
597- text : string ;
598600 originalEncoding : string ;
599601}
600602
601- export interface DidOpenTextDocumentParamsWithOriginalEncoding {
602- textDocument : TextDocumentItemWithOriginalEncoding ;
603- }
604-
605603// Requests
606604const PreInitializationRequest : RequestType < void , string , void > = new RequestType < void , string , void > ( 'cpptools/preinitialize' ) ;
607605const InitializationRequest : RequestType < CppInitializationParams , CppInitializationResult , void > = new RequestType < CppInitializationParams , CppInitializationResult , void > ( 'cpptools/initialize' ) ;
@@ -626,7 +624,7 @@ const CppContextRequest: RequestType<TextDocumentIdentifier, ChatContextResult,
626624const CopilotCompletionContextRequest : RequestType < CopilotCompletionContextParams , CopilotCompletionContextResult , void > = new RequestType < CopilotCompletionContextParams , CopilotCompletionContextResult , void > ( 'cpptools/getCompletionContext' ) ;
627625
628626// Notifications to the server
629- const DidOpenNotification : NotificationType < DidOpenTextDocumentParamsWithOriginalEncoding > = new NotificationType < DidOpenTextDocumentParamsWithOriginalEncoding > ( 'cpptools /didOpen' ) ;
627+ const DidOpenNotification : NotificationType < DidOpenTextDocumentParams > = new NotificationType < DidOpenTextDocumentParams > ( 'textDocument /didOpen' ) ;
630628const FileCreatedNotification : NotificationType < FileChangedParams > = new NotificationType < FileChangedParams > ( 'cpptools/fileCreated' ) ;
631629const FileChangedNotification : NotificationType < FileChangedParams > = new NotificationType < FileChangedParams > ( 'cpptools/fileChanged' ) ;
632630const FileDeletedNotification : NotificationType < FileChangedParams > = new NotificationType < FileChangedParams > ( 'cpptools/fileDeleted' ) ;
@@ -650,6 +648,7 @@ const FinishedRequestCustomConfig: NotificationType<FinishedRequestCustomConfigP
650648const DidChangeSettingsNotification : NotificationType < SettingsParams > = new NotificationType < SettingsParams > ( 'cpptools/didChangeSettings' ) ;
651649const DidChangeVisibleTextEditorsNotification : NotificationType < DidChangeVisibleTextEditorsParams > = new NotificationType < DidChangeVisibleTextEditorsParams > ( 'cpptools/didChangeVisibleTextEditors' ) ;
652650const DidChangeTextEditorVisibleRangesNotification : NotificationType < DidChangeTextEditorVisibleRangesParams > = new NotificationType < DidChangeTextEditorVisibleRangesParams > ( 'cpptools/didChangeTextEditorVisibleRanges' ) ;
651+ const SetOpenFileOriginalEncodingNotification : NotificationType < SetOpenFileOriginalEncodingParams > = new NotificationType < SetOpenFileOriginalEncodingParams > ( 'cpptools/setOpenFileOriginalEncoding' ) ;
653652
654653const CodeAnalysisNotification : NotificationType < CodeAnalysisParams > = new NotificationType < CodeAnalysisParams > ( 'cpptools/runCodeAnalysis' ) ;
655654const PauseCodeAnalysisNotification : NotificationType < void > = new NotificationType < void > ( 'cpptools/pauseCodeAnalysis' ) ;
@@ -1831,32 +1830,35 @@ export class DefaultClient implements Client {
18311830 return changedSettings ;
18321831 }
18331832
1834- private prepareVisibleRanges ( editors : readonly vscode . TextEditor [ ] ) : { [ uri : string ] : Range [ ] } {
1835- const visibleRanges : { [ uri : string ] : Range [ ] } = { } ;
1833+ private prepareVisibleEditorInfo ( editors : readonly vscode . TextEditor [ ] ) : { [ uri : string ] : VisibleEditorInfo } {
1834+ const visibileEditorInfo : { [ uri : string ] : VisibleEditorInfo } = { } ;
18361835 editors . forEach ( editor => {
18371836 // Use a map, to account for multiple editors for the same file.
18381837 // First, we just concat all ranges for the same file.
18391838 const uri : string = editor . document . uri . toString ( ) ;
1840- if ( ! visibleRanges [ uri ] ) {
1841- visibleRanges [ uri ] = [ ] ;
1839+ if ( ! visibileEditorInfo [ uri ] ) {
1840+ visibileEditorInfo [ uri ] = {
1841+ visibleRanges : [ ] ,
1842+ originalEncoding : editor . document . encoding
1843+ } ;
18421844 }
1843- visibleRanges [ uri ] = visibleRanges [ uri ] . concat ( editor . visibleRanges . map ( makeLspRange ) ) ;
1845+ visibileEditorInfo [ uri ] . visibleRanges = visibileEditorInfo [ uri ] . visibleRanges . concat ( editor . visibleRanges . map ( makeLspRange ) ) ;
18441846 } ) ;
18451847
18461848 // We may need to merge visible ranges, if there are multiple editors for the same file,
18471849 // and some of the ranges overlap.
1848- Object . keys ( visibleRanges ) . forEach ( uri => {
1849- visibleRanges [ uri ] = util . mergeOverlappingRanges ( visibleRanges [ uri ] ) ;
1850+ Object . keys ( visibileEditorInfo ) . forEach ( uri => {
1851+ visibileEditorInfo [ uri ] . visibleRanges = util . mergeOverlappingRanges ( visibileEditorInfo [ uri ] . visibleRanges ) ;
18501852 } ) ;
18511853
1852- return visibleRanges ;
1854+ return visibileEditorInfo ;
18531855 }
18541856
18551857 // Handles changes to visible files/ranges, changes to current selection/position,
18561858 // and changes to the active text editor. Should only be called on the primary client.
18571859 public async onDidChangeVisibleTextEditors ( editors : readonly vscode . TextEditor [ ] ) : Promise < void > {
18581860 const params : DidChangeVisibleTextEditorsParams = {
1859- visibleRanges : this . prepareVisibleRanges ( editors )
1861+ visibleEditorInfo : this . prepareVisibleEditorInfo ( editors )
18601862 } ;
18611863 if ( vscode . window . activeTextEditor ) {
18621864 if ( util . isCpp ( vscode . window . activeTextEditor . document ) ) {
@@ -2339,19 +2341,25 @@ export class DefaultClient implements Client {
23392341
23402342 // Only used in crash recovery. Otherwise, VS Code sends didOpen directly to native process (through the protocolFilter).
23412343 public async sendDidOpen ( document : vscode . TextDocument ) : Promise < void > {
2342- const params : DidOpenTextDocumentParamsWithOriginalEncoding = {
2344+ const params : DidOpenTextDocumentParams = {
23432345 textDocument : {
23442346 uri : document . uri . toString ( ) ,
23452347 languageId : document . languageId ,
23462348 version : document . version ,
2347- text : document . getText ( ) ,
2348- originalEncoding : document . encoding
2349+ text : document . getText ( )
23492350 }
23502351 } ;
2351- await this . ready ;
23522352 await this . languageClient . sendNotification ( DidOpenNotification , params ) ;
23532353 }
23542354
2355+ public async sendOpenFileOriginalEncoding ( document : vscode . TextDocument ) : Promise < void > {
2356+ const params : SetOpenFileOriginalEncodingParams = {
2357+ uri : document . uri . toString ( ) ,
2358+ originalEncoding : document . encoding
2359+ } ;
2360+ await this . languageClient . sendNotification ( SetOpenFileOriginalEncodingNotification , params ) ;
2361+ }
2362+
23552363 /**
23562364 * Copilot completion-related requests (e.g. getIncludes and getProjectContext) will have their cancellation tokens cancelled
23572365 * if the current request times out (showing the user completion results without context info),
0 commit comments