public override System.Threading.Tasks.Task<ParsedDocument> Parse (ParseOptions options, System.Threading.CancellationToken cancellationToken) { var fileName = options.FileName; var project = options.Project; var doc = new DefaultParsedDocument (fileName); doc.Flags |= ParsedDocumentFlags.NonSerializable; ProjectInformation pi = ProjectInformationManager.Instance.Get (project); string content = options.Content.Text; string[] contentLines = content.Split (new string[]{Environment.NewLine}, StringSplitOptions.None); var globals = new DefaultUnresolvedTypeDefinition ("", GettextCatalog.GetString ("(Global Scope)")); lock (pi) { // Add containers to type list foreach (LanguageItem li in pi.Containers ()) { if (null == li.Parent && FilePath.Equals (li.File, fileName)) { var tmp = AddLanguageItem (pi, globals, li, contentLines) as IUnresolvedTypeDefinition; if (null != tmp){ /*doc.TopLevelTypeDefinitions.Add (tmp);*/ } } } // Add global category for unscoped symbols foreach (LanguageItem li in pi.InstanceMembers ()) { if (null == li.Parent && FilePath.Equals (li.File, fileName)) { AddLanguageItem (pi, globals, li, contentLines); } } } //doc.TopLevelTypeDefinitions.Add (globals); return System.Threading.Tasks.Task.FromResult((ParsedDocument)doc); }
public override System.Threading.Tasks.Task <ParsedDocument> Parse(MonoDevelop.Ide.TypeSystem.ParseOptions parseOptions, CancellationToken cancellationToken) { OpenRazorDocument currentDocument = GetDocument(parseOptions.FileName); if (currentDocument == null) { return(System.Threading.Tasks.Task.FromResult((ParsedDocument) new RazorCSharpParsedDocument(parseOptions.FileName, new RazorCSharpPageInfo()))); } var context = new RazorCSharpParserContext(parseOptions, currentDocument); lock (currentDocument) { return(Parse(context, cancellationToken)); } }
public override System.Threading.Tasks.Task <ParsedDocument> Parse(MonoDevelop.Ide.TypeSystem.ParseOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { var fileName = options.FileName; var project = options.Project; var result = new VBNetParsedDocument(options, fileName); DateTime time; try { time = System.IO.File.GetLastWriteTimeUtc(fileName); } catch (Exception) { time = DateTime.UtcNow; } result.LastWriteTimeUtc = time; return(Task.FromResult <ParsedDocument> (result)); }
public override System.Threading.Tasks.Task <ParsedDocument> Parse(MonoDevelop.Ide.TypeSystem.ParseOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { var fileName = options.FileName; var project = options.Project; var result = new CSharpParsedDocument(options, fileName); if (project != null) { var projectFile = project.Files.GetFile(fileName); if (projectFile != null && !project.IsCompileable(projectFile.FilePath)) { result.Flags |= ParsedDocumentFlags.NonSerializable; } } if (project != null) { var curDoc = options.RoslynDocument; if (curDoc == null) { var curProject = IdeApp.TypeSystemService.GetCodeAnalysisProject(project); if (curProject != null) { var documentId = IdeApp.TypeSystemService.GetDocumentId(project, fileName); result.DocumentId = documentId; } } } else { var compilerArguments = GetCompilerArguments(project); result.ParsedUnit = CSharpSyntaxTree.ParseText(SourceText.From(options.Content.Text), compilerArguments, fileName); } DateTime time; try { time = System.IO.File.GetLastWriteTimeUtc(fileName); } catch (Exception) { time = DateTime.UtcNow; } result.LastWriteTimeUtc = time; return(Task.FromResult <ParsedDocument> (result)); }
public override System.Threading.Tasks.Task<ParsedDocument> Parse (ParseOptions parseOptions, System.Threading.CancellationToken cancellationToken) { var fileName = parseOptions.FileName; ParsedTemplate template = new ParsedTemplate (fileName); var readOnlyDoc = TextEditorFactory.CreateNewReadonlyDocument (parseOptions.Content, fileName); try { var tk = new Tokeniser (fileName, readOnlyDoc.Text); template.ParseWithoutIncludes (tk); } catch (ParserException ex) { template.LogError (ex.Message, ex.Location); } var errors = new List<Error> (); foreach (System.CodeDom.Compiler.CompilerError err in template.Errors) { errors.Add (new Error (err.IsWarning ? ErrorType.Warning : ErrorType.Error, err.ErrorText, new DocumentLocation (err.Line, err.Column))); } var doc = new T4ParsedDocument (fileName, template.RawSegments, errors); doc.Flags |= ParsedDocumentFlags.NonSerializable; return System.Threading.Tasks.Task.FromResult((ParsedDocument)doc); }
public override System.Threading.Tasks.Task<ParsedDocument> Parse (ParseOptions parseOptions, System.Threading.CancellationToken cancellationToken) { var doc = new MonoDevelop.Xml.Editor.XmlParsedDocument (parseOptions.FileName); doc.Flags = ParsedDocumentFlags.NonSerializable; try { var xmlParser = new XmlParser ( new XmlRootState (new HtmlTagState (), new HtmlClosingTagState (true)), true); xmlParser.Parse (parseOptions.Content.CreateReader ()); doc.XDocument = xmlParser.Nodes.GetRoot (); doc.AddRange (xmlParser.Errors); if (doc.XDocument != null) doc.AddRange (Validate (doc.XDocument)); } catch (Exception ex) { MonoDevelop.Core.LoggingService.LogError ("Unhandled error parsing HTML document", ex); } return System.Threading.Tasks.Task.FromResult((ParsedDocument)doc); }
public override System.Threading.Tasks.Task<ParsedDocument> Parse (ParseOptions parseOptions, System.Threading.CancellationToken cancellationToken) { var doc = new XmlParsedDocument (parseOptions.FileName); doc.Flags |= ParsedDocumentFlags.NonSerializable; try { var xmlParser = new XmlParser (new XmlRootState (), true); xmlParser.Parse (parseOptions.Content.CreateReader ()); doc.XDocument = xmlParser.Nodes.GetRoot (); // TODO error conversion! //doc.Add (xmlParser.Errors); if (doc.XDocument != null && doc.XDocument.RootElement != null) { if (!doc.XDocument.RootElement.IsEnded) doc.XDocument.RootElement.End (xmlParser.Location); } } catch (Exception ex) { MonoDevelop.Core.LoggingService.LogError ("Unhandled error parsing xml document", ex); } return System.Threading.Tasks.Task.FromResult((ParsedDocument)doc); }
public override System.Threading.Tasks.Task<ParsedDocument> Parse (ParseOptions parseOptions, System.Threading.CancellationToken cancellationToken) { var info = new WebFormsPageInfo (); var errors = new List<Error> (); var parser = new XmlParser ( new WebFormsRootState (), true ); try { parser.Parse (parseOptions.Content.CreateReader ()); } catch (Exception ex) { LoggingService.LogError ("Unhandled error parsing ASP.NET document '" + (parseOptions.FileName ?? "") + "'", ex); errors.Add (new Error (ErrorType.Error, GettextCatalog.GetString ("Unhandled error parsing ASP.NET document: {0}", ex.Message))); } // get the errors from the StateEngine parser errors.AddRange (parser.Errors); // populating the PageInfo instance XDocument xDoc = parser.Nodes.GetRoot (); info.Populate (xDoc, errors); var type = AspNetAppProjectFlavor.DetermineWebSubtype (parseOptions.FileName); if (type != info.Subtype) { if (info.Subtype == WebSubtype.None) { errors.Add (new Error (ErrorType.Error, GettextCatalog.GetString ("File directive is missing"), new DocumentLocation (1, 1))); } else { type = info.Subtype; errors.Add (new Error (ErrorType.Warning, GettextCatalog.GetString ("File directive does not match page extension"), new DocumentLocation (1, 1))); } } var result = new WebFormsParsedDocument (parseOptions.FileName, type, info, xDoc); result.AddRange (errors); return System.Threading.Tasks.Task.FromResult((ParsedDocument)result); }
ParsedDocument ParseInternal (ParseOptions options, CancellationToken cancellationToken) { var doc = new XmlParsedDocument (options.FileName); doc.Flags |= ParsedDocumentFlags.NonSerializable; var xmlParser = new XmlParser (new XmlRootState (), true); try { xmlParser.Parse (options.Content.CreateReader ()); } catch (Exception ex) { Core.LoggingService.LogError ("Unhandled error parsing xml document", ex); } doc.XDocument = xmlParser.Nodes.GetRoot (); doc.AddRange (xmlParser.Errors); if (doc.XDocument != null && doc.XDocument.RootElement != null) { if (!doc.XDocument.RootElement.IsEnded) doc.XDocument.RootElement.End (xmlParser.Location); } return doc; }
static async Task<EditorInfo> CreateEditor (string text, bool isInCSharpContext) { string parsedText, editorText; int cursorPosition = text.IndexOf ('$'); int endPos = text.IndexOf ('$', cursorPosition + 1); if (endPos == -1) parsedText = editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1); else { parsedText = text.Substring (0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring (endPos + 1); editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring (endPos + 1); cursorPosition = endPos - 1; } var project = Services.ProjectService.CreateProject ("C#", "AspNetApp"); project.FileName = UnitTests.TestBase.GetTempFile (".csproj"); string file = UnitTests.TestBase.GetTempFile (extension); project.AddFile (file); var sev = new TestViewContent (); sev.Project = project; sev.ContentName = file; sev.Text = editorText; sev.CursorPosition = cursorPosition; var tww = new TestWorkbenchWindow (); tww.ViewContent = sev; var doc = new TestDocument (tww); doc.Editor.FileName = sev.ContentName; doc.UpdateProject (project); solution = new MonoDevelop.Projects.Solution (); solution.DefaultSolutionFolder.AddItem (project); solution.AddConfiguration ("", true); await TypeSystemServiceTestExtensions.LoadSolution (solution); var parser = new RazorTestingParser { Doc = doc }; var options = new ParseOptions { Project = project, FileName = sev.ContentName, Content = new StringTextSource (parsedText) }; var parsedDoc = (RazorCSharpParsedDocument)parser.Parse (options, default(CancellationToken)).Result; doc.HiddenParsedDocument = parsedDoc; var editorExtension = new RazorCSharpEditorExtension (doc, parsedDoc as RazorCSharpParsedDocument, isInCSharpContext); return new EditorInfo { Extension = editorExtension, EditorText = editorText, View = sev }; }
public override async System.Threading.Tasks.Task <ParsedDocument> Parse(MonoDevelop.Ide.TypeSystem.ParseOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { var fileName = options.FileName; var project = options.Project; var result = new CSharpParsedDocument(fileName); if (project != null) { var projectFile = project.Files.GetFile(fileName); if (projectFile != null && !TypeSystemParserNode.IsCompileBuildAction(projectFile.BuildAction)) { result.Flags |= ParsedDocumentFlags.NonSerializable; } } var compilerArguments = GetCompilerArguments(project); SyntaxTree unit = null; if (project != null) { var curDoc = options.RoslynDocument; if (curDoc == null) { var curProject = TypeSystemService.GetCodeAnalysisProject(project); if (curProject != null) { var documentId = TypeSystemService.GetDocumentId(project, fileName); if (documentId != null) { curDoc = curProject.GetDocument(documentId); } } } if (curDoc != null) { try { var model = await curDoc.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); unit = model.SyntaxTree; result.Ast = model; } catch (AggregateException ae) { ae.Flatten().Handle(x => x is OperationCanceledException); return(result); } catch (OperationCanceledException) { return(result); } catch (Exception e) { LoggingService.LogError("Error while getting the semantic model for " + fileName, e); } } } if (unit == null) { unit = CSharpSyntaxTree.ParseText(SourceText.From(options.Content.Text), compilerArguments, fileName); } result.Unit = unit; DateTime time; try { time = System.IO.File.GetLastWriteTimeUtc(fileName); } catch (Exception) { time = DateTime.UtcNow; } result.LastWriteTimeUtc = time; return(result); }
Task ReparseDocumentInternal () { var options = new ParseOptions { FileName = projectedEditor.FileName, Content = projectedEditor, Project = Project, RoslynDocument = projectedDocument, OldParsedDocument = parsedDocument }; return TypeSystemService.ParseFile (options, projectedEditor.MimeType).ContinueWith (t => { parsedDocument = t.Result; base.OnDocumentParsed (EventArgs.Empty); }); }
static WebFormsTestingEditorExtension CreateEditor (string text, string extension, out string editorText, out TestViewContent sev) { string parsedText; int cursorPosition = text.IndexOf ('$'); int endPos = text.IndexOf ('$', cursorPosition + 1); if (endPos == -1) parsedText = editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1); else { parsedText = text.Substring (0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring (endPos + 1); editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring (endPos + 1); cursorPosition = endPos - 1; } var project = Services.ProjectService.CreateDotNetProject ("C#"); project.References.Add (ProjectReference.CreateAssemblyReference ("System")); project.References.Add (ProjectReference.CreateAssemblyReference ("System.Web")); project.FileName = UnitTests.TestBase.GetTempFile (".csproj"); string file = UnitTests.TestBase.GetTempFile (extension); project.AddFile (file); sev = new TestViewContent (); sev.Project = project; sev.ContentName = file; sev.Text = editorText; sev.CursorPosition = cursorPosition; var tww = new TestWorkbenchWindow (); tww.ViewContent = sev; var doc = new TestDocument (tww); doc.Editor.FileName = sev.ContentName; var parser = new WebFormsParser (); var options = new ParseOptions { Project = project, FileName = sev.ContentName, Content = new StringTextSource (parsedText) }; var parsedDoc = (WebFormsParsedDocument)parser.Parse (options, default(CancellationToken)).Result; doc.HiddenParsedDocument = parsedDoc; return new WebFormsTestingEditorExtension (doc); }
public override System.Threading.Tasks.Task<ParsedDocument> Parse (ParseOptions parseOptions, System.Threading.CancellationToken cancellationToken) { ParsedDocument doc = new DefaultParsedDocument (parseOptions.FileName); DefaultUnresolvedTypeDefinition currentFile = null; DefaultUnresolvedProperty currentRegion = null; string eol = Environment.NewLine; string content = parseOptions.Content.Text; Match eolMatch = eolExpression.Match (content); if (eolMatch != null && eolMatch.Success) eol = eolMatch.Groups ["eol"].Value; string[] lines = content.Split (new string[]{eol}, StringSplitOptions.None); int linenum = 1; Match lineMatch; foreach (string line in lines) { lineMatch = fileHeaderExpression.Match (line.Trim ()); if (lineMatch != null && lineMatch.Success) { if (currentFile != null) // Close out previous file region currentFile.BodyRegion = new DomRegion (currentFile.BodyRegion.BeginLine, currentFile.BodyRegion.BeginColumn, linenum - 1, int.MaxValue); if (currentRegion != null) // Close out previous chunk region currentRegion.BodyRegion = new DomRegion (currentRegion.BodyRegion.BeginLine, currentRegion.BodyRegion.BeginColumn, linenum - 1, int.MaxValue); // Create new file region currentFile = new DefaultUnresolvedTypeDefinition (string.Empty, string.Empty); currentFile.Region = currentFile.BodyRegion = new DomRegion (lastToken (lineMatch.Groups ["filepath"].Value), linenum, line.Length + 1, linenum, int.MaxValue); // doc.TopLevelTypeDefinitions.Add (currentFile); } else { lineMatch = chunkExpression.Match (line); if (lineMatch != null && lineMatch.Success && currentFile != null) { if (currentRegion != null) // Close out previous chunk region currentRegion.BodyRegion = new DomRegion (currentRegion.BodyRegion.BeginLine, currentRegion.BodyRegion.BeginColumn, linenum - 1, int.MaxValue); // Create new chunk region currentRegion = new DefaultUnresolvedProperty (currentFile, lineMatch.Groups ["chunk"].Value); currentRegion.Region = currentRegion.BodyRegion = new DomRegion (currentFile.Region.FileName, linenum, line.Length + 1, linenum, int.MaxValue); currentFile.Members.Add (currentRegion); } } ++linenum; } // Close out trailing regions if (currentFile != null) currentFile.BodyRegion = new DomRegion (currentFile.BodyRegion.BeginLine, currentFile.BodyRegion.BeginColumn, Math.Max (1, linenum - 2), int.MaxValue); if (currentRegion != null) currentRegion.BodyRegion = new DomRegion (currentRegion.BodyRegion.BeginLine, currentRegion.BodyRegion.BeginColumn, Math.Max (1, linenum - 2), int.MaxValue); return System.Threading.Tasks.Task.FromResult (doc); }
async Task<RazorCSharpParsedDocument> Parse (string text, bool isPreprocessed) { var project = Services.ProjectService.CreateDotNetProject ("C#", "AspNetApp"); project.FileName = UnitTests.TestBase.GetTempFile (".csproj"); string file = UnitTests.TestBase.GetTempFile (".cshtml"); ProjectFile projectFile = project.AddFile (file); if (isPreprocessed) projectFile.Generator = "RazorTemplatePreprocessor"; var sev = new TestViewContent (); sev.Project = project; sev.ContentName = file; sev.Text = text; var tww = new TestWorkbenchWindow (); tww.ViewContent = sev; var doc = new TestDocument (tww); doc.Editor.FileName = sev.ContentName; doc.UpdateProject (project); solution = new MonoDevelop.Projects.Solution (); solution.DefaultSolutionFolder.AddItem (project); solution.AddConfiguration ("", true); await TypeSystemServiceTestExtensions.LoadSolution (solution); var parser = new RazorTestingParser { Doc = doc }; var options = new ParseOptions { Project = project, FileName = file, Content = new StringTextSource (text) }; return (RazorCSharpParsedDocument)parser.Parse (options, default(CancellationToken)).Result; }
public override Task<ParsedDocument> Parse (ParseOptions options, CancellationToken cancellationToken) { return Task.Run (() => ParseInternal (options, cancellationToken)); }
public RazorCSharpParserContext (MonoDevelop.Ide.TypeSystem.ParseOptions parseOptions, OpenRazorDocument razorDocument) { this.parseOptions = parseOptions; this.razorDocument = razorDocument; }
public override System.Threading.Tasks.Task<ParsedDocument> Parse (ParseOptions parseOptions, System.Threading.CancellationToken cancellationToken) { Doc.Editor.FileName = parseOptions.FileName; OpenDocuments.Add (new OpenRazorDocument (Doc.Editor)); return base.Parse (parseOptions, cancellationToken); }
public RazorCSharpParserContext(MonoDevelop.Ide.TypeSystem.ParseOptions parseOptions, OpenRazorDocument razorDocument) { this.parseOptions = parseOptions; this.razorDocument = razorDocument; }
IEnumerable <DocumentInfo> CreateDocuments(ProjectData projectData, MonoDevelop.Projects.Project p, CancellationToken token, MonoDevelop.Projects.ProjectFile[] sourceFiles) { var duplicates = new HashSet <DocumentId> (); // use given source files instead of project.Files because there may be additional files added by msbuild targets foreach (var f in sourceFiles) { if (token.IsCancellationRequested) { yield break; } if (f.Subtype == MonoDevelop.Projects.Subtype.Directory) { continue; } if (TypeSystemParserNode.IsCompileBuildAction(f.BuildAction)) { if (!duplicates.Add(projectData.GetOrCreateDocumentId(f.Name))) { continue; } yield return(CreateDocumentInfo(solutionData, p.Name, projectData, f)); continue; } var mimeType = DesktopService.GetMimeTypeForUri(f.FilePath); var node = TypeSystemService.GetTypeSystemParserNode(mimeType, f.BuildAction); if (node == null || !node.Parser.CanGenerateProjection(mimeType, f.BuildAction, p.SupportedLanguages)) { continue; } var options = new ParseOptions { FileName = f.FilePath, Project = p, Content = StringTextSource.ReadFrom(f.FilePath), }; var projections = node.Parser.GenerateProjections(options); var entry = new ProjectionEntry(); entry.File = f; var list = new List <Projection> (); entry.Projections = list; foreach (var projection in projections.Result) { list.Add(projection); if (!duplicates.Add(projectData.GetOrCreateDocumentId(projection.Document.FileName))) { continue; } var plainName = projection.Document.FileName.FileName; yield return(DocumentInfo.Create( projectData.GetOrCreateDocumentId(projection.Document.FileName), plainName, new [] { p.Name }.Concat(f.ProjectVirtualPath.ParentDirectory.ToString().Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)), SourceCodeKind.Regular, TextLoader.From(TextAndVersion.Create(new MonoDevelopSourceText(projection.Document), VersionStamp.Create(), projection.Document.FileName)), projection.Document.FileName, false )); } projectionList.Add(entry); } }