private static ImmutableArray <DefinitionItem> GetIncludeDefinitionItem(LogicalDocument document, SyntaxToken syntaxToken) { var includeDirective = (IncludeDirectiveTriviaSyntax)syntaxToken.Parent; var syntaxTree = document.GetSyntaxTreeSynchronously(CancellationToken.None); var workspace = document.Workspace; var includeFileSystem = workspace.Services.GetRequiredService <IWorkspaceIncludeFileSystem>(); var parseOptions = (HlslParseOptions)syntaxTree.Options; var includeFileResolver = new IncludeFileResolver(includeFileSystem, parseOptions); var currentFile = ((SyntaxTree)syntaxTree).File; var include = includeFileResolver.OpenInclude(includeDirective.TrimmedFilename, currentFile); if (include == null) { return(ImmutableArray <DefinitionItem> .Empty); } var fileSpan = new CodeAnalysis.Text.SourceFileSpan(include, new CodeAnalysis.Text.TextSpan(0, 0)); var definitionItem = DefinitionItem.Create( ImmutableArray <string> .Empty, ImmutableArray <TaggedText> .Empty, new DocumentSpan(document, fileSpan), ImmutableArray <TaggedText> .Empty); return(ImmutableArray.Create(definitionItem)); }
protected override bool Execute(VSConstants.VSStd2KCmdID commandId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { var includeDirectiveTrivia = GetIncludeDirective(); if (includeDirectiveTrivia == null) { return(false); } var includeFileResolver = new IncludeFileResolver(_textView.TextBuffer.GetIncludeFileSystem(_sourceTextFactory)); var include = includeFileResolver.OpenInclude( includeDirectiveTrivia.TrimmedFilename, _textView.TextBuffer.GetTextContainer().Filename, _textView.TextBuffer.GetTextContainer().Filename, _textView.TextBuffer.GetConfigFile().HlslAdditionalIncludeDirectories); if (include == null) { return(false); } _serviceProvider.NavigateTo(include.Filename, 0, 0, 0, 0); return(true); }
public bool ExecuteCommand(OpenFileCommandArgs args, CommandExecutionContext context) { var includeDirectiveTrivia = GetIncludeDirective(args.TextView, args.SubjectBuffer); if (includeDirectiveTrivia == null) { return(false); } var document = args.SubjectBuffer.AsTextContainer().GetOpenDocumentInCurrentContext(); var syntaxTree = document.GetSyntaxTreeSynchronously(CancellationToken.None); var workspace = document.Workspace; var includeFileSystem = workspace.Services.GetRequiredService <IWorkspaceIncludeFileSystem>(); var parseOptions = (HlslParseOptions)syntaxTree.Options; var includeFileResolver = new IncludeFileResolver(includeFileSystem, parseOptions); var currentFile = ((SyntaxTree)syntaxTree).File; var include = includeFileResolver.OpenInclude(includeDirectiveTrivia.TrimmedFilename, currentFile); if (include == null) { var errorMessage = new StringBuilder(); errorMessage.AppendLine($"Cannot open source file '{includeDirectiveTrivia.TrimmedFilename}'."); errorMessage.AppendLine(); errorMessage.AppendLine("Searched paths:"); foreach (var includeDirectory in includeFileResolver.GetSearchDirectories(includeDirectiveTrivia.TrimmedFilename, currentFile)) { errorMessage.AppendLine(includeDirectory); } context.OperationContext.TakeOwnership(); var notificationService = workspace.Services.GetService <INotificationService>(); notificationService.SendNotification( errorMessage.ToString(), title: "Open Include File", severity: NotificationSeverity.Information); return(true); } var documentNavigationService = workspace.Services.GetRequiredService <IDocumentNavigationService>(); documentNavigationService.TryNavigateToSpan( workspace, document.Id, new SourceFileSpan(include, new TextSpan(0, 0))); return(true); }