@@ -100,6 +100,53 @@ export class ClangdContext implements vscode.Disposable {
100100 // Do not switch to output window when clangd returns output.
101101 revealOutputChannelOn : vscodelc . RevealOutputChannelOn . Never ,
102102
103+ // https://github.com/clangd/vscode-clangd/issues/726
104+ // Remove this workaround once clangd fixes the issue on their side: https://github.com/clangd/clangd/issues/108
105+ uriConverters : {
106+ code2Protocol : ( uri : vscode . Uri ) : string => {
107+ if ( uri . scheme === 'file' ) {
108+ function fix_windows_drive_letter_casing ( uri : vscode . Uri ) : string | undefined {
109+ // We can't just use process.platform === 'win32' because of remote development
110+
111+ // https://stackoverflow.com/a/64822303/4479969
112+ // detect windows paths
113+ const isWindowsPathRegex = / ^ (?< drive > [ a - z ] : ) ? (?< path > (?: [ \\ ] ? (?: [ \w ! # ( ) - ] + | [ . ] { 1 , 2 } ) + ) * [ \\ ] ) ? (?< filename > (?: [ . ] ? [ \w ! # ( ) - ] + ) + ) ? [ . ] ? $ / i;
114+
115+ // Fix lower case drive letters on Windows
116+ const fsPath = uri . fsPath
117+
118+ const windowsPathMatch = fsPath . match ( isWindowsPathRegex ) ;
119+
120+ if ( ! windowsPathMatch ) {
121+ // we are not dealing with a windows path
122+ return undefined ;
123+ }
124+
125+ // change the drive letter to uppercase
126+ const drive = windowsPathMatch . groups ?. drive ?. toUpperCase ( ) ?? '' ;
127+ const path = windowsPathMatch . groups ?. path ?? '' ;
128+ const filename = windowsPathMatch . groups ?. filename ?? '' ;
129+
130+ if ( ! drive ) {
131+ // no drive letter so there is nothing to fix
132+ return undefined ;
133+ }
134+
135+ // Reconstruct the path
136+ const fixed_uri = `file:///${ drive } ${ path } ${ filename } ` ;
137+ return fixed_uri ;
138+ }
139+
140+ const fixed_uri = fix_windows_drive_letter_casing ( uri ) ;
141+ if ( fixed_uri ) {
142+ return fixed_uri ;
143+ }
144+ }
145+ return uri . toString ( ) ;
146+ } ,
147+ protocol2Code : ( uri : string ) => vscode . Uri . parse ( uri ) ,
148+ } ,
149+
103150 // We hack up the completion items a bit to prevent VSCode from re-ranking
104151 // and throwing away all our delicious signals like type information.
105152 //
0 commit comments