public IReadOnlyList <Diagnostic> GetDiagnostics(DocumentId documentId, int start, int length) { var document = CurrentSolution.GetDocument(documentId); var semanticModel = document.GetSemanticModelAsync().Result; var bounds = TextSpan.FromBounds(start, start + length); var diagnostics = semanticModel.GetDiagnostics(bounds); return(diagnostics.ToArray()); }
public ISymbol GetSymbol(DocumentId documentId, int position) { var document = CurrentSolution.GetDocument(documentId); var semanticModel = document.GetSemanticModelAsync().Result; var root = semanticModel.SyntaxTree.GetRoot(); var symbol = root.FindToken(position); return(semanticModel.GetSymbolInfo(symbol.Parent).Symbol); }
public void DispatchSolutionUnload(SolutionEventArgs e) { CurrentSolution.Dispose(); CurrentSolution = null; if (SolutionUnload != null) { SolutionUnload(this, e); } }
public IReadOnlyList <MethodDeclarationSyntax> GetMethods(DocumentId documentId) { var document = CurrentSolution.GetDocument(documentId); var syntaxTree = document.GetSyntaxTreeAsync().Result; var root = syntaxTree.GetRoot(); return(root.DescendantNodes().OfType <MethodDeclarationSyntax>().ToArray()); }
public Task <IReadOnlyList <Diagnostic> > GetDiagnosticsAsync(DocumentId documentId, CancellationToken cancellationToken) { return(Task.Run(async() => { var project = CurrentSolution.GetProject(documentId.ProjectId); var compilation = await project.GetCompilationAsync(cancellationToken); return (IReadOnlyList <Diagnostic>)compilation.GetDiagnostics(cancellationToken); }, cancellationToken)); }
public void EnsureBufferUpdated(Request request) { foreach (var documentId in CurrentSolution.GetDocumentIdsWithFilePath(request.FileName)) { var buffer = Encoding.UTF8.GetBytes(request.Buffer); var sourceText = SourceText.From(new MemoryStream(buffer), encoding: Encoding.UTF8); OnDocumentChanged(documentId, sourceText); } }
public IEnumerable <ClassifiedSpan> GetClassifiedSpans(DocumentId documentId, int start, int length) { var document = CurrentSolution.GetDocument(documentId); return(ThreadHelper.JoinableTaskFactory.RunAsync(async() => { return await Classifier.GetClassifiedSpansAsync(document, TextSpan.FromBounds(start, start + length)).ConfigureAwait(true); }).Join()); }
public Task FormatDocumentAsync(DocumentId documentId) { return(Task.Run(async() => { var formattedDocument = await Microsoft.CodeAnalysis.Formatting.Formatter.FormatAsync( CurrentSolution.GetDocument(documentId) !).ConfigureAwait(false); TryApplyChanges(formattedDocument.Project.Solution); })); }
public string FormatDocument(DocumentId documentId) { var document = CurrentSolution.GetDocument(documentId); document = Formatter.FormatAsync(document).Result; var text = document.GetTextAsync().Result; return(text.ToString()); }
//Add private void Button_Click_3(object sender, RoutedEventArgs e) { if (!string.IsNullOrWhiteSpace(NewFileNameText.Text)) { if (SelectedFileType == NewFileType.Window) { if (!NewFileNameText.Text.Contains(".xaml")) { NewFileNameText.Text += ".xaml"; } File.WriteAllText(Path.Combine(CurrentSolution.SourceDirectory, NewFileNameText.Text), Constants.CreateNewXamlWindowFile(CurrentSolution, NewFileNameText.Text)); File.WriteAllText(Path.Combine(CurrentSolution.SourceDirectory, NewFileNameText.Text + ".cs"), Constants.CreateNewXamlCsFile(CurrentSolution, NewFileNameText.Text)); CurrentSolution.AddProjectFile(NewFileNameText.Text, false); CurrentSolution.AddProjectFile(NewFileNameText.Text + ".cs"); CurrentWorkspace.AddProjectFile(NewFileNameText.Text); CurrentWorkspace.AddProjectFile(NewFileNameText.Text + ".cs"); CurrentSolution.Save(); this.Close(); } else if (SelectedFileType == NewFileType.UserControl) { if (!NewFileNameText.Text.Contains(".xaml")) { NewFileNameText.Text += ".xaml"; } File.WriteAllText(Path.Combine(CurrentSolution.SourceDirectory, NewFileNameText.Text), Constants.CreateNewXamlControlFile(CurrentSolution, NewFileNameText.Text)); File.WriteAllText(Path.Combine(CurrentSolution.SourceDirectory, NewFileNameText.Text + ".cs"), Constants.CreateNewXamlCsFile(CurrentSolution, NewFileNameText.Text, true)); CurrentSolution.AddProjectFile(NewFileNameText.Text, false); CurrentSolution.AddProjectFile(NewFileNameText.Text + ".cs"); CurrentWorkspace.AddProjectFile(NewFileNameText.Text); CurrentWorkspace.AddProjectFile(NewFileNameText.Text + ".cs"); CurrentSolution.Save(); this.Close(); } else if (SelectedFileType == NewFileType.Class) { if (!NewFileNameText.Text.Contains(".cs")) { NewFileNameText.Text += ".cs"; } File.WriteAllText(Path.Combine(CurrentSolution.SourceDirectory, NewFileNameText.Text), Constants.CreateNewClass(CurrentSolution, NewFileNameText.Text)); CurrentSolution.AddProjectFile(NewFileNameText.Text); CurrentWorkspace.AddProjectFile(NewFileNameText.Text); CurrentSolution.Save(); this.Close(); } else { MessageBox.Show("You must select a new file type.", "Need User Input", MessageBoxButton.OK); } } else { MessageBox.Show("You must select a new file type.", "Need User Input", MessageBoxButton.OK); } }
protected override void ApplyDocumentTextChanged(DocumentId documentId, SourceText text) { var document = CurrentSolution.GetDocument(documentId); if (document?.FilePath != null && text.Encoding != null) { SaveDocumentText(documentId, document.FilePath, text, text.Encoding); OnDocumentTextChanged(documentId, text, PreservationMode.PreserveValue); } }
public override void OpenDocument(DocumentId documentId, bool activate = true) { var doc = CurrentSolution.GetDocument(documentId); if (doc != null) { var text = doc.GetTextAsync(CancellationToken.None).WaitAndGetResult(CancellationToken.None); OnDocumentOpened(documentId, text.Container, activate); } }
public Task <IReadOnlyList <ISymbol> > GetRecommendedSymbolsAsync(DocumentId documentId, int position, CancellationToken cancellationToken) { return(Task.Run(async() => { var document = CurrentSolution.GetDocument(documentId); var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); var symbols = await Recommender.GetRecommendedSymbolsAtPositionAsync(semanticModel, position, this, null, cancellationToken).ConfigureAwait(false); return (IReadOnlyList <ISymbol>)symbols.ToArray(); }, cancellationToken)); }
public TemporaryWorkspace(HostServices hostServices, string?workspaceKind, SolutionInfo solutionInfo, SerializableOptionSet options) : base(hostServices, workspaceKind) { var documentOptionsProviderFactories = ((IMefHostExportProvider)Services.HostServices).GetExports <IDocumentOptionsProviderFactory, OrderableMetadata>(); RegisterDocumentOptionProviders(documentOptionsProviderFactories); OnSolutionAdded(solutionInfo); SetCurrentSolution(CurrentSolution.WithOptions(options)); }
public Document? GetOrAddExternalDocument(string filePath, string language) { var docId = CurrentSolution.GetDocumentIdsWithFilePath(filePath).FirstOrDefault(); if (docId != null) { return CurrentSolution.GetDocument(docId); } return AddDocumentToProject(filePath, language, ExternalProjectName); }
public Document GetDocument(string filePath) { var documentId = GetDocumentId(filePath); if (documentId == null) { return(null); } return(CurrentSolution.GetDocument(documentId)); }
public EmitResult Compile(DocumentId documentId, string path) { var document = CurrentSolution.GetDocument(documentId); var compilation = document.Project.GetCompilationAsync().Result; using (var fileStream = File.Create(path)) { return(compilation.Emit(fileStream)); } }
protected override void ApplyDocumentTextChanged(DocumentId id, SourceText text) { base.ApplyDocumentTextChanged(id, text); var document = CurrentSolution.GetDocument(id); if (document != null) { OnDocumentTextChanged(id, text, PreservationMode.PreserveValue); } }
public Document GetDocument(DocumentId documentId, CancellationToken cancellationToken = default(CancellationToken)) { var project = CurrentSolution.GetProject(documentId.ProjectId); if (project == null) { return(null); } return(project.GetDocument(documentId)); }
public static void AddProductToCurrentSolution(Product productToAdd) { CurrentSolution.AddProductToSolution(productToAdd); subtotaltracker += productToAdd.Price; taxestracker = subtotaltracker * .0625; //MA Tax Rate finaltotaltracker = subtotaltracker * 1.0625; CurrentSolution.Subtotal = subtotaltracker.ToString(); CurrentSolution.Taxes = taxestracker.ToString(); CurrentSolution.FinalTotal = finaltotaltracker.ToString(); }
/// <summary> /// Finds the <see cref="DocumentId"/> related to the given <see cref="DocumentId"/> that /// is in the current context. For regular files (non-shared and non-linked) and closed /// linked files, this is always the provided <see cref="DocumentId"/>. For open linked /// files and open shared files, the active context is already tracked by the /// <see cref="Workspace"/> and can be looked up directly. For closed shared files, the /// document in the shared project's <see cref="__VSHPROPID7.VSHPROPID_SharedItemContextHierarchy"/> /// is preferred. /// </summary> internal override DocumentId GetDocumentIdInCurrentContext(DocumentId documentId) { // If the document is open, then the Workspace knows the current context for both // linked and shared files if (IsDocumentOpen(documentId)) { return(base.GetDocumentIdInCurrentContext(documentId)); } var hostDocument = GetHostDocument(documentId); if (hostDocument == null) { // This can happen if the document was temporary and has since been closed/deleted. return(base.GetDocumentIdInCurrentContext(documentId)); } var itemId = hostDocument.GetItemId(); if (itemId == (uint)VSConstants.VSITEMID.Nil) { // An itemid is required to determine whether the file belongs to a Shared Project return(base.GetDocumentIdInCurrentContext(documentId)); } // If this is a regular document or a closed linked (non-shared) document, then use the // default logic for determining current context. var sharedHierarchy = LinkedFileUtilities.GetSharedHierarchyForItem(hostDocument.Project.Hierarchy, itemId); if (sharedHierarchy == null) { return(base.GetDocumentIdInCurrentContext(documentId)); } // This is a closed shared document, so we must determine the correct context. var hostProject = LinkedFileUtilities.GetContextHostProject(sharedHierarchy, DeferredState.ProjectTracker); var matchingProject = CurrentSolution.GetProject(hostProject.Id); if (matchingProject == null || hostProject.Hierarchy == sharedHierarchy) { return(base.GetDocumentIdInCurrentContext(documentId)); } if (matchingProject.ContainsDocument(documentId)) { // The provided documentId is in the current context project return(documentId); } // The current context document is from another project. var linkedDocumentIds = CurrentSolution.GetDocument(documentId).GetLinkedDocumentIds(); var matchingDocumentId = linkedDocumentIds.FirstOrDefault(id => id.ProjectId == matchingProject.Id); return(matchingDocumentId ?? base.GetDocumentIdInCurrentContext(documentId)); }
DocumentId CreateDocumentId(string filePath) { var project = CurrentSolution.Projects.First(); var projectId = project.Id; var documentId = DocumentId.CreateNewId(projectId, debugName: filePath); var documentInfo = DocumentInfo.Create(documentId, filePath); var solution = CurrentSolution.AddDocument(documentInfo); SetCurrentSolution(solution); return(documentId); }
public override void OpenDocument(DocumentId documentId, bool activate = true) { var document = CurrentSolution.GetDocument(documentId); if (document != null) { var sourceText = document.GetTextAsync(CancellationToken.None).Result; openDocumentState = openDocumentState.Add(documentId, new DocumentState()); OnDocumentOpened(documentId, sourceText.Container, activate); } }
public Document AddDocument(DocumentInfo documentInfo) { if (documentInfo == null) { throw new ArgumentNullException(nameof(documentInfo)); } OnDocumentAdded(documentInfo); return(CurrentSolution.GetDocument(documentInfo.Id)); }
public DocumentId GetDocumentId(AvalonStudio.Projects.ISourceFile file) { var ids = CurrentSolution.GetDocumentIdsWithFilePath(file.Location); if (ids.Length != 1) { throw new NotImplementedException(); } return(ids.First()); }
public string FormatDocument(DocumentId documentId) { var document = CurrentSolution.GetDocument(documentId); return(ThreadHelper.JoinableTaskFactory.RunAsync(async() => { document = await Formatter.FormatAsync(document).ConfigureAwait(true); var text = await document.GetTextAsync().ConfigureAwait(true); return text.ToString(); }).Join()); }
public IReadOnlyList <ISymbol> GetRecommendedSymbols(DocumentId documentId, int position) { var document = CurrentSolution.GetDocument(documentId); return(ThreadHelper.JoinableTaskFactory.RunAsync(async() => { var semanticModel = await document.GetSemanticModelAsync().ConfigureAwait(true); var result = Recommender.GetRecommendedSymbolsAtPosition(semanticModel, position, this); return result.ToArray(); }).Join()); }
public void CallDocumentClosingAndClosed_CsFile(DocumentId documentId) { OnDocumentClosing(documentId); var document = CurrentSolution.GetDocument(documentId); if (document != null && document.TryGetText(out var text)) { OnDocumentClosed(documentId, TextLoader.From(TextAndVersion.Create(text, VersionStamp.Default, document.FilePath))); } }
public Project AddProject(ProjectInfo projectInfo) { if (projectInfo == null) { throw new ArgumentNullException(nameof(projectInfo)); } OnProjectAdded(projectInfo); UpdateReferencesAfterAdd(); return(CurrentSolution.GetProject(projectInfo.Id)); }
public void NotifyOnDocumentClosing(string moniker) { if (_openedDocs.TryGetValue(moniker, out DocumentId id)) { // check if the doc is part of the current Roslyn workspace before notifying Roslyn. if (CurrentSolution.ContainsProject(id.ProjectId)) { OnDocumentClosed(id, new FileTextLoaderNoException(moniker, null)); _openedDocs = _openedDocs.Remove(moniker); } } }