Skip to content

Commit 0e0b72f

Browse files
committed
Pull Metadata document if it isn't present in client
1 parent c9fed9f commit 0e0b72f

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

src/features/definitionMetadataDocumentProvider.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { IDisposable } from '../Disposable';
99

1010
export default class DefinitionMetadataDocumentProvider implements TextDocumentContentProvider, IDisposable {
1111
readonly scheme = "omnisharp-metadata";
12-
private _registration : IDisposable;
12+
private _registration: IDisposable;
1313
private _documents: Map<string, MetadataResponse>;
1414
private _documentClosedSubscription: IDisposable;
1515

@@ -18,36 +18,41 @@ export default class DefinitionMetadataDocumentProvider implements TextDocumentC
1818
this._documentClosedSubscription = workspace.onDidCloseTextDocument(this.onTextDocumentClosed, this);
1919
}
2020

21-
private onTextDocumentClosed(document: TextDocument) : void {
21+
private onTextDocumentClosed(document: TextDocument): void {
2222
this._documents.delete(document.uri.toString());
2323
}
2424

25-
public dispose() : void {
25+
public dispose(): void {
2626
this._registration.dispose();
2727
this._documentClosedSubscription.dispose();
2828
this._documents.clear();
2929
}
3030

31-
public addMetadataResponse(metadataResponse: MetadataResponse) : Uri {
31+
public addMetadataResponse(metadataResponse: MetadataResponse): Uri {
3232
const uri = this.createUri(metadataResponse.SourceName);
3333
this._documents.set(uri.toString(), metadataResponse);
3434

3535
return uri;
3636
}
3737

38-
public getExistingMetadataResponseUri(sourceName: string) : Uri {
38+
public getExistingMetadataResponseUri(sourceName: string): Uri {
3939
return this.createUri(sourceName);
4040
}
4141

42-
public register() : void {
42+
public hasMetadataDocument(sourceName: string): boolean {
43+
const uri = this.createUri(sourceName);
44+
return this._documents.has(uri.toString());
45+
}
46+
47+
public register(): void {
4348
this._registration = workspace.registerTextDocumentContentProvider(this.scheme, this);
4449
}
4550

46-
public provideTextDocumentContent(uri: Uri) : string {
47-
return this._documents.get(uri.toString()).Source;
51+
public provideTextDocumentContent(uri: Uri): string {
52+
return this._documents.get(uri.toString())?.Source;
4853
}
4954

50-
private createUri(sourceName: string) : Uri {
55+
private createUri(sourceName: string): Uri {
5156
return Uri.parse(this.scheme + "://" +
5257
sourceName.replace(/\\/g, "/").replace(/(.*)\/(.*)/g, "$1/[metadata] $2"));
5358
}

src/features/definitionProvider.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,22 @@ export default class CSharpDefinitionProvider extends AbstractSupport implements
3434
if (gotoDefinitionResponse && gotoDefinitionResponse.Definitions) {
3535

3636
for (const definition of gotoDefinitionResponse.Definitions) {
37-
if (definition.Location.FileName.startsWith("$metadata$")) {
38-
// if it is part of an already used metadata file, retrieve its uri instead of going to the physical file
39-
const uri = this.definitionMetadataDocumentProvider.getExistingMetadataResponseUri(definition.Location.FileName);
40-
const vscodeRange = toRange3(definition.Location.Range);
41-
locations.push(new Location(uri, vscodeRange));
42-
} else if (definition.MetadataSource) {
37+
if (definition.MetadataSource) {
4338
// the definition is in metadata
4439
const metadataSource: MetadataSource = definition.MetadataSource;
4540

46-
// go to metadata endpoint for more information
41+
// Do we already have a document for this metadata reference?
42+
if (definition.Location.FileName.startsWith("$metadata$") &&
43+
this.definitionMetadataDocumentProvider.hasMetadataDocument(definition.Location.FileName)) {
44+
45+
// if it is part of an already used metadata file, retrieve its uri instead of going to the physical file
46+
const uri = this.definitionMetadataDocumentProvider.getExistingMetadataResponseUri(definition.Location.FileName);
47+
const vscodeRange = toRange3(definition.Location.Range);
48+
locations.push(new Location(uri, vscodeRange));
49+
continue;
50+
}
51+
52+
// We need to go to the metadata endpoint for more information
4753
const metadataResponse = await serverUtils.getMetadata(this._server, <MetadataRequest>{
4854
Timeout: 5000,
4955
AssemblyName: metadataSource.AssemblyName,

0 commit comments

Comments
 (0)