@@ -28,7 +28,7 @@ import * as fs from 'fs';
28
28
import * as os from 'os' ;
29
29
import { SourceFileConfiguration , SourceFileConfigurationItem , Version , WorkspaceBrowseConfiguration } from 'vscode-cpptools' ;
30
30
import { 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' ;
32
32
import { LanguageClient , ServerOptions } from 'vscode-languageclient/node' ;
33
33
import * as nls from 'vscode-nls' ;
34
34
import { DebugConfigurationProvider } from '../Debugger/configurationProvider' ;
@@ -517,10 +517,15 @@ interface TagParseStatus {
517
517
isPaused : boolean ;
518
518
}
519
519
520
+ interface VisibleEditorInfo {
521
+ visibleRanges : Range [ ] ;
522
+ originalEncoding : string ;
523
+ }
524
+
520
525
interface DidChangeVisibleTextEditorsParams {
521
526
activeUri ?: string ;
522
527
activeSelection ?: Range ;
523
- visibleRanges ?: { [ uri : string ] : Range [ ] } ;
528
+ visibleEditorInfo ?: { [ uri : string ] : VisibleEditorInfo } ;
524
529
}
525
530
526
531
interface DidChangeTextEditorVisibleRangesParams {
@@ -590,18 +595,11 @@ export interface CopilotCompletionContextParams {
590
595
doAggregateSnippets : boolean ;
591
596
}
592
597
593
- export interface TextDocumentItemWithOriginalEncoding {
598
+ export interface SetOpenFileOriginalEncodingParams {
594
599
uri : string ;
595
- languageId : string ;
596
- version : number ;
597
- text : string ;
598
600
originalEncoding : string ;
599
601
}
600
602
601
- export interface DidOpenTextDocumentParamsWithOriginalEncoding {
602
- textDocument : TextDocumentItemWithOriginalEncoding ;
603
- }
604
-
605
603
// Requests
606
604
const PreInitializationRequest : RequestType < void , string , void > = new RequestType < void , string , void > ( 'cpptools/preinitialize' ) ;
607
605
const InitializationRequest : RequestType < CppInitializationParams , CppInitializationResult , void > = new RequestType < CppInitializationParams , CppInitializationResult , void > ( 'cpptools/initialize' ) ;
@@ -626,8 +624,7 @@ const CppContextRequest: RequestType<TextDocumentIdentifier, ChatContextResult,
626
624
const CopilotCompletionContextRequest : RequestType < CopilotCompletionContextParams , CopilotCompletionContextResult , void > = new RequestType < CopilotCompletionContextParams , CopilotCompletionContextResult , void > ( 'cpptools/getCompletionContext' ) ;
627
625
628
626
// Notifications to the server
629
- const DidOpenNotification : NotificationType < DidOpenTextDocumentParamsWithOriginalEncoding > = new NotificationType < DidOpenTextDocumentParamsWithOriginalEncoding > ( 'cpptools/didOpen' ) ;
630
- const FileCreatedNotification : NotificationType < FileChangedParams > = new NotificationType < FileChangedParams > ( 'cpptools/fileCreated' ) ;
627
+ const DidOpenNotification : NotificationType < DidOpenTextDocumentParams > = new NotificationType < DidOpenTextDocumentParams > ( 'textDocument/didOpen' ) ; const FileCreatedNotification : NotificationType < FileChangedParams > = new NotificationType < FileChangedParams > ( 'cpptools/fileCreated' ) ;
631
628
const FileChangedNotification : NotificationType < FileChangedParams > = new NotificationType < FileChangedParams > ( 'cpptools/fileChanged' ) ;
632
629
const FileDeletedNotification : NotificationType < FileChangedParams > = new NotificationType < FileChangedParams > ( 'cpptools/fileDeleted' ) ;
633
630
const ResetDatabaseNotification : NotificationType < void > = new NotificationType < void > ( 'cpptools/resetDatabase' ) ;
@@ -650,6 +647,7 @@ const FinishedRequestCustomConfig: NotificationType<FinishedRequestCustomConfigP
650
647
const DidChangeSettingsNotification : NotificationType < SettingsParams > = new NotificationType < SettingsParams > ( 'cpptools/didChangeSettings' ) ;
651
648
const DidChangeVisibleTextEditorsNotification : NotificationType < DidChangeVisibleTextEditorsParams > = new NotificationType < DidChangeVisibleTextEditorsParams > ( 'cpptools/didChangeVisibleTextEditors' ) ;
652
649
const DidChangeTextEditorVisibleRangesNotification : NotificationType < DidChangeTextEditorVisibleRangesParams > = new NotificationType < DidChangeTextEditorVisibleRangesParams > ( 'cpptools/didChangeTextEditorVisibleRanges' ) ;
650
+ const SetOpenFileOriginalEncodingNotification : NotificationType < SetOpenFileOriginalEncodingParams > = new NotificationType < SetOpenFileOriginalEncodingParams > ( 'cpptools/setOpenFileOriginalEncoding' ) ;
653
651
654
652
const CodeAnalysisNotification : NotificationType < CodeAnalysisParams > = new NotificationType < CodeAnalysisParams > ( 'cpptools/runCodeAnalysis' ) ;
655
653
const PauseCodeAnalysisNotification : NotificationType < void > = new NotificationType < void > ( 'cpptools/pauseCodeAnalysis' ) ;
@@ -1831,32 +1829,35 @@ export class DefaultClient implements Client {
1831
1829
return changedSettings ;
1832
1830
}
1833
1831
1834
- private prepareVisibleRanges ( editors : readonly vscode . TextEditor [ ] ) : { [ uri : string ] : Range [ ] } {
1835
- const visibleRanges : { [ uri : string ] : Range [ ] } = { } ;
1832
+ private prepareVisibleEditorInfo ( editors : readonly vscode . TextEditor [ ] ) : { [ uri : string ] : VisibleEditorInfo } {
1833
+ const visibileEditorInfo : { [ uri : string ] : VisibleEditorInfo } = { } ;
1836
1834
editors . forEach ( editor => {
1837
1835
// Use a map, to account for multiple editors for the same file.
1838
1836
// First, we just concat all ranges for the same file.
1839
1837
const uri : string = editor . document . uri . toString ( ) ;
1840
- if ( ! visibleRanges [ uri ] ) {
1841
- visibleRanges [ uri ] = [ ] ;
1838
+ if ( ! visibileEditorInfo [ uri ] ) {
1839
+ visibileEditorInfo [ uri ] = {
1840
+ visibleRanges : [ ] ,
1841
+ originalEncoding : editor . document . encoding
1842
+ } ;
1842
1843
}
1843
- visibleRanges [ uri ] = visibleRanges [ uri ] . concat ( editor . visibleRanges . map ( makeLspRange ) ) ;
1844
+ visibileEditorInfo [ uri ] . visibleRanges = visibileEditorInfo [ uri ] . visibleRanges . concat ( editor . visibleRanges . map ( makeLspRange ) ) ;
1844
1845
} ) ;
1845
1846
1846
1847
// We may need to merge visible ranges, if there are multiple editors for the same file,
1847
1848
// and some of the ranges overlap.
1848
- Object . keys ( visibleRanges ) . forEach ( uri => {
1849
- visibleRanges [ uri ] = util . mergeOverlappingRanges ( visibleRanges [ uri ] ) ;
1849
+ Object . keys ( visibileEditorInfo ) . forEach ( uri => {
1850
+ visibileEditorInfo [ uri ] . visibleRanges = util . mergeOverlappingRanges ( visibileEditorInfo [ uri ] . visibleRanges ) ;
1850
1851
} ) ;
1851
1852
1852
- return visibleRanges ;
1853
+ return visibileEditorInfo ;
1853
1854
}
1854
1855
1855
1856
// Handles changes to visible files/ranges, changes to current selection/position,
1856
1857
// and changes to the active text editor. Should only be called on the primary client.
1857
1858
public async onDidChangeVisibleTextEditors ( editors : readonly vscode . TextEditor [ ] ) : Promise < void > {
1858
1859
const params : DidChangeVisibleTextEditorsParams = {
1859
- visibleRanges : this . prepareVisibleRanges ( editors )
1860
+ visibleEditorInfo : this . prepareVisibleEditorInfo ( editors )
1860
1861
} ;
1861
1862
if ( vscode . window . activeTextEditor ) {
1862
1863
if ( util . isCpp ( vscode . window . activeTextEditor . document ) ) {
@@ -2339,19 +2340,25 @@ export class DefaultClient implements Client {
2339
2340
2340
2341
// Only used in crash recovery. Otherwise, VS Code sends didOpen directly to native process (through the protocolFilter).
2341
2342
public async sendDidOpen ( document : vscode . TextDocument ) : Promise < void > {
2342
- const params : DidOpenTextDocumentParamsWithOriginalEncoding = {
2343
+ const params : DidOpenTextDocumentParams = {
2343
2344
textDocument : {
2344
2345
uri : document . uri . toString ( ) ,
2345
2346
languageId : document . languageId ,
2346
2347
version : document . version ,
2347
- text : document . getText ( ) ,
2348
- originalEncoding : document . encoding
2348
+ text : document . getText ( )
2349
2349
}
2350
2350
} ;
2351
- await this . ready ;
2352
2351
await this . languageClient . sendNotification ( DidOpenNotification , params ) ;
2353
2352
}
2354
2353
2354
+ public async sendOpenFileOriginalEncoding ( document : vscode . TextDocument ) : Promise < void > {
2355
+ const params : SetOpenFileOriginalEncodingParams = {
2356
+ uri : document . uri . toString ( ) ,
2357
+ originalEncoding : document . encoding
2358
+ } ;
2359
+ await this . languageClient . sendNotification ( SetOpenFileOriginalEncodingNotification , params ) ;
2360
+ }
2361
+
2355
2362
/**
2356
2363
* Copilot completion-related requests (e.g. getIncludes and getProjectContext) will have their cancellation tokens cancelled
2357
2364
* if the current request times out (showing the user completion results without context info),
0 commit comments