private void SetupServices() { var componentModel = GetService <SComponentModel, IComponentModel>(); var outputWindowService = componentModel.DefaultExportProvider.GetExportedValueOrDefault <IOutputWindowService>(); IOutputWindowPane gitHubPane = null; // Warn users if dependencies aren't installed. vsbaseWarningProvider = new ErrorListProvider(this); if (outputWindowService != null) { gitHubPane = outputWindowService.TryGetPane(OutputWriter.GitHubOutputWindowPaneName); } else { var task = new ErrorTask { Category = TaskCategory.Misc, ErrorCategory = TaskErrorCategory.Error, Text = "The required VSBase Services debugging support extension is not installed; output window messages will not be shown. Click here for more information." }; task.Navigate += HandleNavigateToVsBaseServicesExtension; vsbaseWarningProvider.Tasks.Add(task); vsbaseWarningProvider.Show(); } // This code is a bit of a hack to bridge MEF created components and Ninject managed components Factory.Rebind <IOutputWindowPane>().ToConstant(gitHubPane); Factory.Rebind <ICache>().ToConstant(componentModel.DefaultExportProvider.GetExportedValue <Cache>()); Factory.Rebind <IOptionsProvider>().ToConstant(this); }
///////////////////////////////////////////////////////////////////////////// // Overridden Package Implementation #region Package Members /// <summary> /// Initialization of the package; this method is called right after the package is sited, so this is the place /// where you can put all the initialization code that rely on services provided by VisualStudio. /// </summary> protected override void Initialize() { Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", ToString())); base.Initialize(); // Add our command handlers for menu (commands must exist in the .vsct file) var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null != mcs) { // Create the command for the menu item. var menuCommandID = new CommandID(GuidList.guidGitHubExtensionCmdSet, (int)PkgCmdIDList.cmdidNewIssue); var menuItem = new MenuCommand(MenuItemCallback, menuCommandID); mcs.AddCommand(menuItem); // Create the commands for the tool windows var issueListWndCommandID = new CommandID(GuidList.guidGitHubExtensionCmdSet, (int)PkgCmdIDList.cmdidIssues); var menuIssueListWin = new MenuCommand(ShowIssueListToolWindow, issueListWndCommandID); mcs.AddCommand(menuIssueListWin); var issueWndCommandID = new CommandID(GuidList.guidGitHubExtensionCmdSet, (int)PkgCmdIDList.cmdidIssueWindow); var menuIssueWin = new MenuCommand(ShowIssueToolWindow, issueWndCommandID); mcs.AddCommand(menuIssueWin); var tfsIssueListWndCommandID = new CommandID(GuidList.guidGitHubExtensionCmdSet, (int)PkgCmdIDList.cmdidTfsIssues); var menuTfsIssueListWin = new MenuCommand(ShowTfsIssueListToolWindow, tfsIssueListWndCommandID); mcs.AddCommand(menuTfsIssueListWin); //var tfsIssueWndCommandID = new CommandID(GuidList.guidGitHubExtensionCmdSet, (int)PkgCmdIDList.cmdidTfsIssueWindow); //var menuTfsIssueWin = new MenuCommand(ShowTfsIssueToolWindow, tfsIssueWndCommandID); //mcs.AddCommand(menuTfsIssueWin); } IComponentModel componentModel = (IComponentModel)GetService(typeof(SComponentModel)); IOutputWindowService outputWindowService = componentModel.DefaultExportProvider.GetExportedValueOrDefault <IOutputWindowService>(); IOutputWindowPane gitHubPane = null; // Warn users if dependencies aren't installed. vsbaseWarningProvider = new ErrorListProvider(this); if (outputWindowService != null) { gitHubPane = outputWindowService.TryGetPane(View.OutputWriter.GitHubOutputWindowPaneName); } else { ErrorTask task = new ErrorTask { Category = TaskCategory.Misc, ErrorCategory = TaskErrorCategory.Error, Text = "The required VSBase Services debugging support extension is not installed; output window messages will not be shown. Click here for more information." }; task.Navigate += HandleNavigateToVsBaseServicesExtension; vsbaseWarningProvider.Tasks.Add(task); vsbaseWarningProvider.Show(); } // This code is a bit of a hack to bridge MEF created components and Ninject managed components Factory.Rebind <IOutputWindowPane>().ToConstant(gitHubPane); Factory.Rebind <ICache>().ToConstant(componentModel.DefaultExportProvider.GetExportedValue <Cache>()); }
public ErrorListener(string fileName, List<ParseErrorEventArgs> errors, IOutputWindowPane outputWindow) { Contract.Requires<ArgumentNullException>(errors != null, "errors"); _fileName = fileName; _errors = errors; _outputWindow = outputWindow; }
public void TestPredefinedGeneralPane() { IOutputWindowService outputWindowService = OutputWindowService; IOutputWindowPane pane = outputWindowService.TryGetPane(PredefinedOutputWindowPanes.General); Assert.IsInstanceOfType(pane, typeof(IOutputWindowPane)); TestOutputPaneBehavior(pane, PredefinedOutputWindowPanes.General); }
public void TestTvlIntellisensePane() { IOutputWindowService outputWindowService = OutputWindowService; IOutputWindowPane pane = outputWindowService.TryGetPane(PredefinedOutputWindowPanes.TvlIntellisense); Assert.IsInstanceOfType(pane, typeof(IOutputWindowPane)); TestStandardPanes.TestOutputPaneBehavior(pane, PredefinedOutputWindowPanes.TvlIntellisense); }
public ErrorListener(string fileName, List <ParseErrorEventArgs> errors, IOutputWindowPane outputWindow) { Requires.NotNull(errors, nameof(errors)); _fileName = fileName; _errors = errors; _outputWindow = outputWindow; }
public ErrorListener(string fileName, List <ParseErrorEventArgs> errors, IOutputWindowPane outputWindow) { Contract.Requires <ArgumentNullException>(errors != null, "errors"); _fileName = fileName; _errors = errors; _outputWindow = outputWindow; }
public Antlr4SmartIndent(Antlr4SmartIndentProvider provider, IOutputWindowPane diagnosticsPane) : base(diagnosticsPane) { _provider = provider; var shell = provider.ServiceProvider.GetShell(); var package = shell.LoadPackage <AntlrLanguagePackage>(); _languageInfo = package.GetService <Antlr4LanguageInfo>(); }
internal static void TestOutputPaneBehavior(IOutputWindowPane pane, string initialName) { Assert.IsNotNull(pane); Assert.AreEqual(initialName, pane.Name); pane.Activate(); pane.Hide(); pane.Activate(); string newName = pane.Name + " - " + Path.GetRandomFileName(); pane.Name = newName; Assert.AreEqual(newName, pane.Name); pane.Write("Writing text..."); pane.WriteLine(" done."); }
public void TestRenameCustomPaneDoesNotAffectPaneLookup() { IOutputWindowService outputWindowService = OutputWindowService; IOutputWindowPane pane = outputWindowService.TryGetPane(PredefinedOutputWindowPanes.TvlDiagnostics); Assert.IsInstanceOfType(pane, typeof(IOutputWindowPane)); string newName = PredefinedOutputWindowPanes.TvlDiagnostics + " Something Else"; pane.Name = newName; IOutputWindowPane retry = outputWindowService.TryGetPane(PredefinedOutputWindowPanes.TvlDiagnostics); Assert.IsInstanceOfType(pane, typeof(IOutputWindowPane)); Assert.AreEqual(newName, retry.Name); retry.Name = PredefinedOutputWindowPanes.TvlDiagnostics; Assert.AreEqual(PredefinedOutputWindowPanes.TvlDiagnostics, pane.Name); }
public ExecutionContext(IOutputWindowPane pane, Dispatcher dispatcher, System.Diagnostics.Process process, bool debug, DTE2 dte, IIdeTracer tracer, Version specRunVersion) { this.pane = pane; this.dispatcher = dispatcher; this.process = process; this.debug = debug; this.dte = dte; this.tracer = tracer; this.specRunVersion = specRunVersion; if (specRunVersion >= SpecRun12) { shouldAttachToMain = null; } process.OutputDataReceived += OnMessageReceived; process.ErrorDataReceived += OnMessageReceived; }
public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; var triggerPoint = session.GetTriggerPoint(buffer.CurrentSnapshot); if (triggerPoint == null) { return; } ITextDocument doc; if (!provider.TextDocumentFactoryService.TryGetTextDocument(buffer, out doc)) { return; } IOutputWindowPane diagnostics = provider.OutputWindowService.TryGetPane(OutputWindowPanes.DartVSDiagnostics); if (diagnostics != null) { diagnostics.WriteLine("Quick info requested for: " + doc.FilePath); } // Figure out if this is a recalculate for an existing span (not sure if this is the best way of supporting async...?) if (inProgressPosition != null && inProgressPosition.Value == triggerPoint.Value.Position) { UpdateTooltip(session, quickInfoContent, out applicableToSpan); } else { applicableToSpan = GetApplicableToSpan(triggerPoint); var ignoredTask = StartTooltipRequestAsync(session, quickInfoContent, applicableToSpan, triggerPoint, doc.FilePath); } }
protected override void ReParseImpl() { Stopwatch timer = Stopwatch.StartNew(); // lex the entire document to get the set of identifiers we'll need to classify ITextSnapshot snapshot = TextBuffer.CurrentSnapshot; var input = new SnapshotCharStream(snapshot, new Span(0, snapshot.Length)); var lexer = new GoLexer(input); var tokenSource = new GoSemicolonInsertionTokenSource(lexer); var tokens = new CommonTokenStream(tokenSource); tokens.Fill(); /* easy to handle the following definitions: * - module (name) * - open (external symbol reference) ... as (name) * - fact (name)? * - assert (name)? * - fun (ref.name | name) * - pred (ref.name | name) * - (name): run|check * - sig (namelist) * - enum (name) * moderate to handle the following definitions: * - decl name(s) * harder to handle the following definitions: */ /* A single name follows the following keywords: * - KW_MODULE * - KW_OPEN * - KW_AS * - KW_ENUM * - KW_FACT (name is optional) * - KW_ASSERT (name is optional) */ List <IToken> nameKeywords = new List <IToken>(); List <IToken> declColons = new List <IToken>(); List <IToken> identifiers = new List <IToken>(); while (tokens.LA(1) != CharStreamConstants.EndOfFile) { switch (tokens.LA(1)) { case GoLexer.IDENTIFIER: identifiers.Add(tokens.LT(1)); break; case GoLexer.KW_PACKAGE: case GoLexer.KW_IMPORT: case GoLexer.KW_TYPE: case GoLexer.KW_VAR: case GoLexer.KW_FUNC: case GoLexer.KW_CONST: //case GoLexer.KW_MODULE: //case GoLexer.KW_OPEN: //case GoLexer.KW_AS: //case GoLexer.KW_ENUM: //case GoLexer.KW_FACT: //case GoLexer.KW_ASSERT: //case GoLexer.KW_RUN: //case GoLexer.KW_CHECK: //case GoLexer.KW_EXTENDS: //case GoLexer.KW_FUN: //case GoLexer.KW_PRED: //case GoLexer.KW_SIG: nameKeywords.Add(tokens.LT(1)); break; case GoLexer.DEFEQ: case GoLexer.COLON: declColons.Add(tokens.LT(1)); break; case CharStreamConstants.EndOfFile: goto doneLexing; default: break; } tokens.Consume(); } doneLexing: HashSet <IToken> definitions = new HashSet <IToken>(TokenIndexEqualityComparer.Default); HashSet <IToken> references = new HashSet <IToken>(TokenIndexEqualityComparer.Default); foreach (var token in nameKeywords) { tokens.Seek(token.TokenIndex); NetworkInterpreter interpreter = CreateTopLevelNetworkInterpreter(tokens); while (interpreter.TryStepForward()) { if (interpreter.Contexts.Count == 0 || interpreter.Contexts.Count > 400) { break; } if (interpreter.Contexts.All(context => context.BoundedEnd)) { break; } } interpreter.CombineBoundedEndContexts(); foreach (var context in interpreter.Contexts) { foreach (var transition in context.Transitions) { if (!transition.Symbol.HasValue) { continue; } switch (transition.Symbol) { case GoLexer.IDENTIFIER: //case GoLexer.KW_THIS: RuleBinding rule = interpreter.Network.StateRules[transition.Transition.TargetState.Id]; if (rule.Name == GoSimplifiedAtnBuilder.RuleNames.SymbolReferenceIdentifier) { references.Add(tokens.Get(transition.TokenIndex.Value)); } else if (rule.Name == GoSimplifiedAtnBuilder.RuleNames.SymbolDefinitionIdentifier) { definitions.Add(tokens.Get(transition.TokenIndex.Value)); } break; default: continue; } } } } foreach (var token in declColons) { tokens.Seek(token.TokenIndex); tokens.Consume(); if (token.Type == GoLexer.COLON) { IToken potentialLabel = tokens.LT(-2); if (potentialLabel.Type != GoLexer.IDENTIFIER) { continue; } } NetworkInterpreter interpreter = CreateVarDeclarationNetworkInterpreter(tokens); while (interpreter.TryStepBackward()) { if (interpreter.Contexts.Count == 0 || interpreter.Contexts.Count > 400) { break; } if (interpreter.Contexts.All(context => context.BoundedStart)) { break; } interpreter.Contexts.RemoveAll(i => !IsConsistentWithPreviousResult(i, true, definitions, references)); } interpreter.CombineBoundedStartContexts(); if (!AllAgree(interpreter.Contexts)) { while (interpreter.TryStepForward()) { if (interpreter.Contexts.Count == 0 || interpreter.Contexts.Count > 400) { break; } if (interpreter.Contexts.All(context => context.BoundedEnd)) { break; } interpreter.Contexts.RemoveAll(i => !IsConsistentWithPreviousResult(i, false, definitions, references)); } interpreter.CombineBoundedEndContexts(); } foreach (var context in interpreter.Contexts) { foreach (var transition in context.Transitions) { if (!transition.Symbol.HasValue) { continue; } switch (transition.Symbol) { case GoLexer.IDENTIFIER: //case GoLexer.KW_THIS: RuleBinding rule = interpreter.Network.StateRules[transition.Transition.TargetState.Id]; if (rule.Name == GoSimplifiedAtnBuilder.RuleNames.SymbolReferenceIdentifier) { references.Add(tokens.Get(transition.TokenIndex.Value)); } else if (rule.Name == GoSimplifiedAtnBuilder.RuleNames.SymbolDefinitionIdentifier) { definitions.Add(tokens.Get(transition.TokenIndex.Value)); } break; default: continue; } } } } #if false foreach (var token in identifiers) { if (definitions.Contains(token) || references.Contains(token)) { continue; } tokens.Seek(token.TokenIndex); tokens.Consume(); NetworkInterpreter interpreter = CreateFullNetworkInterpreter(tokens); while (interpreter.TryStepBackward()) { if (interpreter.Contexts.Count == 0 || interpreter.Contexts.Count > 400) { break; } if (interpreter.Contexts.All(context => context.BoundedStart)) { break; } interpreter.Contexts.RemoveAll(i => !IsConsistentWithPreviousResult(i, true, definitions, references)); if (AllAgree(interpreter.Contexts)) { break; } } interpreter.CombineBoundedStartContexts(); while (interpreter.TryStepForward()) { if (interpreter.Contexts.Count == 0 || interpreter.Contexts.Count > 400) { break; } if (interpreter.Contexts.All(context => context.BoundedEnd)) { break; } interpreter.Contexts.RemoveAll(i => !IsConsistentWithPreviousResult(i, false, definitions, references)); if (AllAgree(interpreter.Contexts)) { break; } } interpreter.CombineBoundedEndContexts(); foreach (var context in interpreter.Contexts) { foreach (var transition in context.Transitions) { if (!transition.Symbol.HasValue) { continue; } switch (transition.Symbol) { case GoLexer.IDENTIFIER: //case GoLexer.KW_THIS: RuleBinding rule = interpreter.Network.StateRules[transition.Transition.TargetState.Id]; if (rule.Name == GoSimplifiedAtnBuilder.RuleNames.SymbolReferenceIdentifier) { references.Add(tokens.Get(transition.TokenIndex.Value)); } else if (rule.Name == GoSimplifiedAtnBuilder.RuleNames.SymbolDefinitionIdentifier) { definitions.Add(tokens.Get(transition.TokenIndex.Value)); } break; default: continue; } } } } #endif // tokens which are in both the 'definitions' and 'references' sets are actually unknown. HashSet <IToken> unknownIdentifiers = new HashSet <IToken>(definitions, TokenIndexEqualityComparer.Default); unknownIdentifiers.IntersectWith(references); definitions.ExceptWith(unknownIdentifiers); #if true references = new HashSet <IToken>(identifiers, TokenIndexEqualityComparer.Default); references.ExceptWith(definitions); references.ExceptWith(unknownIdentifiers); #else references.ExceptWith(unknownIdentifiers); // the full set of unknown identifiers are any that aren't explicitly classified as a definition or a reference unknownIdentifiers = new HashSet <IToken>(identifiers, TokenIndexEqualityComparer.Default); unknownIdentifiers.ExceptWith(definitions); unknownIdentifiers.ExceptWith(references); #endif List <ITagSpan <IClassificationTag> > tags = new List <ITagSpan <IClassificationTag> >(); IClassificationType definitionClassificationType = _classificationTypeRegistryService.GetClassificationType(GoSymbolTaggerClassificationTypeNames.Definition); tags.AddRange(ClassifyTokens(snapshot, definitions, new ClassificationTag(definitionClassificationType))); IClassificationType referenceClassificationType = _classificationTypeRegistryService.GetClassificationType(GoSymbolTaggerClassificationTypeNames.Reference); tags.AddRange(ClassifyTokens(snapshot, references, new ClassificationTag(referenceClassificationType))); IClassificationType unknownClassificationType = _classificationTypeRegistryService.GetClassificationType(GoSymbolTaggerClassificationTypeNames.UnknownIdentifier); tags.AddRange(ClassifyTokens(snapshot, unknownIdentifiers, new ClassificationTag(unknownClassificationType))); _tags = tags; timer.Stop(); IOutputWindowPane pane = OutputWindowService.TryGetPane(PredefinedOutputWindowPanes.TvlIntellisense); if (pane != null) { pane.WriteLine(string.Format("Finished classifying {0} identifiers in {1}ms: {2} definitions, {3} references, {4} unknown", identifiers.Count, timer.ElapsedMilliseconds, definitions.Count, references.Count, unknownIdentifiers.Count)); } OnTagsChanged(new SnapshotSpanEventArgs(new SnapshotSpan(snapshot, new Span(0, snapshot.Length)))); }
private void ReParse() { try { _dirty = false; IOutputWindowPane outputWindow = null; if (_outputWindowService != null && !string.IsNullOrEmpty(_outputWindowName)) { outputWindow = _outputWindowService.TryGetPane(_outputWindowName); } Stopwatch stopwatch = Stopwatch.StartNew(); string message = "{0}: Background parse {1}{2} in {3}ms. {4}"; string name = Name; if (!string.IsNullOrEmpty(name)) { name = "(" + name + ") "; } string filename = "<Unknown File>"; ITextDocument textDocument = TextDocument; if (textDocument != null) { filename = textDocument.FilePath; if (filename != null) { filename = filename.Substring(filename.LastIndexOfAny(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }) + 1); } } try { ReParseImpl(); if (outputWindow != null) { long time = stopwatch.ElapsedMilliseconds; outputWindow.WriteLine(string.Format(message, filename, name, "succeeded", time, string.Empty)); } } catch (Exception e2) { if (ErrorHandler.IsCriticalException(e2)) { throw; } try { if (outputWindow != null) { long time = stopwatch.ElapsedMilliseconds; outputWindow.WriteLine(string.Format(message, filename, name, "failed", time, e2.Message + e2.StackTrace)); } } catch (Exception e3) { if (ErrorHandler.IsCriticalException(e3)) { throw; } } } } catch (Exception ex) { if (ErrorHandler.IsCriticalException(ex)) { throw; } } }
public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; if (session == null || quickInfoContent == null) { return; } if (session.TextView.TextBuffer == this.TextBuffer) { ITextSnapshot currentSnapshot = this.TextBuffer.CurrentSnapshot; SnapshotPoint?triggerPoint = session.GetTriggerPoint(currentSnapshot); if (!triggerPoint.HasValue) { return; } #region experimental /* use the experimental model to locate and process the expression */ Stopwatch stopwatch = Stopwatch.StartNew(); // lex the entire document var input = new SnapshotCharStream(currentSnapshot, new Span(0, currentSnapshot.Length)); var lexer = new GoLexer(input); var tokenSource = new GoSemicolonInsertionTokenSource(lexer); var tokens = new CommonTokenStream(tokenSource); tokens.Fill(); // locate the last token before the trigger point while (true) { IToken nextToken = tokens.LT(1); if (nextToken.Type == CharStreamConstants.EndOfFile) { break; } if (nextToken.StartIndex > triggerPoint.Value.Position) { break; } tokens.Consume(); } switch (tokens.LA(-1)) { case GoLexer.IDENTIFIER: //case GoLexer.KW_THIS: //case GoLexer.KW_UNIV: //case GoLexer.KW_IDEN: //case GoLexer.KW_INT2: //case GoLexer.KW_SEQINT: break; default: return; } Network network = NetworkBuilder <GoSimplifiedAtnBuilder> .GetOrBuildNetwork(); RuleBinding memberSelectRule = network.GetRule(GoSimplifiedAtnBuilder.RuleNames.PrimaryExpr); #if false HashSet <Transition> memberSelectTransitions = new HashSet <Transition>(); GetReachableTransitions(memberSelectRule, memberSelectTransitions); #endif NetworkInterpreter interpreter = new NetworkInterpreter(network, tokens); interpreter.BoundaryRules.Add(memberSelectRule); interpreter.BoundaryRules.Add(network.GetRule(GoSimplifiedAtnBuilder.RuleNames.Label)); interpreter.BoundaryRules.Add(network.GetRule(GoSimplifiedAtnBuilder.RuleNames.TypeSwitchGuard)); interpreter.BoundaryRules.Add(network.GetRule(GoSimplifiedAtnBuilder.RuleNames.FieldName)); interpreter.BoundaryRules.Add(network.GetRule(GoSimplifiedAtnBuilder.RuleNames.Receiver)); interpreter.BoundaryRules.Add(network.GetRule(GoSimplifiedAtnBuilder.RuleNames.FunctionDecl)); interpreter.BoundaryRules.Add(network.GetRule(GoSimplifiedAtnBuilder.RuleNames.BaseTypeName)); interpreter.BoundaryRules.Add(network.GetRule(GoSimplifiedAtnBuilder.RuleNames.TypeSpec)); interpreter.BoundaryRules.Add(network.GetRule(GoSimplifiedAtnBuilder.RuleNames.IdentifierList)); interpreter.BoundaryRules.Add(network.GetRule(GoSimplifiedAtnBuilder.RuleNames.MethodName)); interpreter.BoundaryRules.Add(network.GetRule(GoSimplifiedAtnBuilder.RuleNames.ParameterDecl)); interpreter.BoundaryRules.Add(network.GetRule(GoSimplifiedAtnBuilder.RuleNames.FieldIdentifierList)); interpreter.BoundaryRules.Add(network.GetRule(GoSimplifiedAtnBuilder.RuleNames.PackageName)); interpreter.BoundaryRules.Add(network.GetRule(GoSimplifiedAtnBuilder.RuleNames.TypeName)); interpreter.ExcludedStartRules.Add(network.GetRule(GoSimplifiedAtnBuilder.RuleNames.Block)); while (interpreter.TryStepBackward()) { if (interpreter.Contexts.Count == 0) { break; } /* we want all traces to start outside the binOpExpr18 rule, which means all * traces with a transition reachable from binOpExpr18 should contain a push * transition with binOpExpr18's start state as its target. */ if (interpreter.Contexts.All(context => context.BoundedStart)) { break; } } interpreter.CombineBoundedStartContexts(); IOutputWindowPane pane = Provider.OutputWindowService.TryGetPane(PredefinedOutputWindowPanes.TvlIntellisense); if (pane != null) { pane.WriteLine(string.Format("Located {0} QuickInfo expression(s) in {1}ms.", interpreter.Contexts.Count, stopwatch.ElapsedMilliseconds)); } HashSet <string> finalResult = new HashSet <string>(); SnapshotSpan? contextSpan = null; foreach (var context in interpreter.Contexts) { Span?span = null; //List<string> results = AnalyzeInterpreterTrace(context, memberSelectRule, out span); foreach (var transition in context.Transitions) { if (!transition.Transition.IsMatch) { continue; } IToken token = transition.Token; Span tokenSpan = new Span(token.StartIndex, token.StopIndex - token.StartIndex + 1); if (span == null) { span = tokenSpan; } else { span = Span.FromBounds(Math.Min(span.Value.Start, tokenSpan.Start), Math.Max(span.Value.End, tokenSpan.End)); } } if (span.HasValue && !span.Value.IsEmpty) { contextSpan = new SnapshotSpan(currentSnapshot, span.Value); } //if (results.Count > 0) //{ // finalResult.UnionWith(results); // applicableToSpan = currentSnapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeExclusive); //} } foreach (var result in finalResult) { quickInfoContent.Add(result); } #endregion #if false var selection = session.TextView.Selection.StreamSelectionSpan; if (selection.IsEmpty || !selection.Contains(new VirtualSnapshotPoint(triggerPoint.Value))) { SnapshotSpan?expressionSpan = Provider.IntellisenseCache.GetExpressionSpan(triggerPoint.Value); if (expressionSpan.HasValue) { selection = new VirtualSnapshotSpan(expressionSpan.Value); } } #endif VirtualSnapshotSpan selection = new VirtualSnapshotSpan(); if (contextSpan.HasValue) { selection = new VirtualSnapshotSpan(contextSpan.Value); } if (!selection.IsEmpty && selection.Contains(new VirtualSnapshotPoint(triggerPoint.Value))) { applicableToSpan = selection.Snapshot.CreateTrackingSpan(selection.SnapshotSpan, SpanTrackingMode.EdgeExclusive); quickInfoContent.Add(selection.GetText()); //try //{ // Expression currentExpression = Provider.IntellisenseCache.ParseExpression(selection); // if (currentExpression != null) // { // SnapshotSpan? span = currentExpression.Span; // if (span.HasValue) // applicableToSpan = span.Value.Snapshot.CreateTrackingSpan(span.Value, SpanTrackingMode.EdgeExclusive); // quickInfoContent.Add(currentExpression.ToString()); // } // else // { // quickInfoContent.Add("Could not parse expression."); // } //} //catch (Exception ex) when (!ErrorHandler.IsCriticalException(ex)) //{ // quickInfoContent.Add(ex.Message); //} } } }
public ExecutionContext(IOutputWindowPane pane, Dispatcher dispatcher, System.Diagnostics.Process process, bool debug, DTE2 dte, IIdeTracer tracer, Version specRunVersion) { this.pane = pane; this.dispatcher = dispatcher; this.process = process; this.debug = debug; this.dte = dte; this.tracer = tracer; this.specRunVersion = specRunVersion; if (specRunVersion >= SpecRun12) shouldAttachToMain = null; process.OutputDataReceived += OnMessageReceived; process.ErrorDataReceived += OnMessageReceived; }
protected SmartIndent(IOutputWindowPane diagnosticsPane) { _diagnosticsPane = diagnosticsPane; }
public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; if (session == null || quickInfoContent == null) { return; } if (session.TextView.TextBuffer == this.TextBuffer) { ITextSnapshot currentSnapshot = this.TextBuffer.CurrentSnapshot; SnapshotPoint?triggerPoint = session.GetTriggerPoint(currentSnapshot); if (!triggerPoint.HasValue) { return; } #region experimental /* use the experimental model to locate and process the expression */ Stopwatch stopwatch = Stopwatch.StartNew(); // lex the entire document var input = new SnapshotCharStream(currentSnapshot, new Span(0, currentSnapshot.Length)); var lexer = new AlloyLexer(input); var tokens = new CommonTokenStream(lexer); tokens.Fill(); // locate the last token before the trigger point while (true) { IToken nextToken = tokens.LT(1); if (nextToken.Type == CharStreamConstants.EndOfFile) { break; } if (nextToken.StartIndex > triggerPoint.Value.Position) { break; } tokens.Consume(); } switch (tokens.LA(-1)) { case AlloyLexer.IDENTIFIER: case AlloyLexer.KW_THIS: case AlloyLexer.KW_UNIV: case AlloyLexer.KW_IDEN: case AlloyLexer.KW_INT2: case AlloyLexer.KW_SEQINT: case AlloyLexer.INTEGER: break; default: return; } Network network = NetworkBuilder <AlloySimplifiedAtnBuilder> .GetOrBuildNetwork(); RuleBinding memberSelectRule = network.GetRule(AlloySimplifiedAtnBuilder.RuleNames.BinOpExpr18); #if DEBUG && false HashSet <Transition> memberSelectTransitions = new HashSet <Transition>(ObjectReferenceEqualityComparer <Transition> .Default); GetReachableTransitions(memberSelectRule, memberSelectTransitions); #endif NetworkInterpreter interpreter = new NetworkInterpreter(network, tokens); interpreter.BoundaryRules.Add(memberSelectRule); //interpreter.BoundaryRules.Add(network.GetRule(AlloySimplifiedAtnBuilder.RuleNames.UnaryExpression)); interpreter.BoundaryRules.Add(network.GetRule(AlloySimplifiedAtnBuilder.RuleNames.LetDecl)); interpreter.BoundaryRules.Add(network.GetRule(AlloySimplifiedAtnBuilder.RuleNames.NameListName)); interpreter.BoundaryRules.Add(network.GetRule(AlloySimplifiedAtnBuilder.RuleNames.Ref)); interpreter.BoundaryRules.Add(network.GetRule(AlloySimplifiedAtnBuilder.RuleNames.Module)); interpreter.BoundaryRules.Add(network.GetRule(AlloySimplifiedAtnBuilder.RuleNames.Open)); interpreter.BoundaryRules.Add(network.GetRule(AlloySimplifiedAtnBuilder.RuleNames.FactDecl)); interpreter.BoundaryRules.Add(network.GetRule(AlloySimplifiedAtnBuilder.RuleNames.AssertDecl)); interpreter.BoundaryRules.Add(network.GetRule(AlloySimplifiedAtnBuilder.RuleNames.FunctionName)); interpreter.BoundaryRules.Add(network.GetRule(AlloySimplifiedAtnBuilder.RuleNames.CmdDecl)); interpreter.BoundaryRules.Add(network.GetRule(AlloySimplifiedAtnBuilder.RuleNames.Typescope)); interpreter.BoundaryRules.Add(network.GetRule(AlloySimplifiedAtnBuilder.RuleNames.EnumDecl)); interpreter.BoundaryRules.Add(network.GetRule(AlloySimplifiedAtnBuilder.RuleNames.ElseClause)); interpreter.ExcludedStartRules.Add(network.GetRule(AlloySimplifiedAtnBuilder.RuleNames.CallArguments)); while (interpreter.TryStepBackward()) { if (interpreter.Contexts.Count == 0) { break; } /* we want all traces to start outside the binOpExpr18 rule, which means all * traces with a transition reachable from binOpExpr18 should contain a push * transition with binOpExpr18's start state as its target. */ if (interpreter.Contexts.All(context => context.BoundedStart)) { break; } } HashSet <InterpretTrace> contexts = new HashSet <InterpretTrace>(BoundedStartInterpretTraceEqualityComparer.Default); if (interpreter.Contexts.Count > 0) { contexts.UnionWith(interpreter.Contexts); } else { contexts.UnionWith(interpreter.BoundedStartContexts); } IOutputWindowPane pane = Provider.OutputWindowService.TryGetPane(PredefinedOutputWindowPanes.TvlIntellisense); if (pane != null) { pane.WriteLine(string.Format("Located {0} QuickInfo expression(s) in {1}ms.", contexts.Count, stopwatch.ElapsedMilliseconds)); } HashSet <Span> spans = new HashSet <Span>(); foreach (var context in contexts) { Span?span = null; foreach (var transition in context.Transitions) { if (!transition.Transition.IsMatch) { continue; } IToken token = transition.Token; Span tokenSpan = new Span(token.StartIndex, token.StopIndex - token.StartIndex + 1); if (span == null) { span = tokenSpan; } else { span = Span.FromBounds(Math.Min(span.Value.Start, tokenSpan.Start), Math.Max(span.Value.End, tokenSpan.End)); } } if (span.HasValue) { spans.Add(span.Value); } } //List<Expression> expressions = new List<Expression>(); //HashSet<string> finalResult = new HashSet<string>(); //SnapshotSpan? contextSpan = null; bool foundInfo = false; foreach (var span in spans) { if (!span.IsEmpty) { VirtualSnapshotSpan selection = new VirtualSnapshotSpan(new SnapshotSpan(currentSnapshot, span)); if (!selection.IsEmpty && selection.Contains(new VirtualSnapshotPoint(triggerPoint.Value))) { try { Expression currentExpression = Provider.IntellisenseCache.ParseExpression(selection); if (currentExpression != null && currentExpression.Span.HasValue && currentExpression.Span.Value.Contains(triggerPoint.Value)) { applicableToSpan = currentExpression.Span.Value.Snapshot.CreateTrackingSpan(currentExpression.Span.Value, SpanTrackingMode.EdgeExclusive); quickInfoContent.Add(currentExpression.ToString()); foundInfo = true; } } catch (Exception ex) { if (ErrorHandler.IsCriticalException(ex)) { throw; } quickInfoContent.Add(ex.Message); } } //try //{ // SnapshotSpan contextSpan = new SnapshotSpan(currentSnapshot, span.Value); // Expression expression = Provider.IntellisenseCache.ParseExpression(contextSpan); // if (expression != null) // expressions.Add(expression); //} //catch (Exception e) //{ // if (ErrorHandler.IsCriticalException(e)) // throw; //} } //if (results.Count > 0) //{ // finalResult.UnionWith(results); // applicableToSpan = currentSnapshot.CreateTrackingSpan(span, SpanTrackingMode.EdgeExclusive); //} } if (!foundInfo && spans.Count > 0) { foreach (var span in spans) { if (!span.IsEmpty) { VirtualSnapshotSpan selection = new VirtualSnapshotSpan(new SnapshotSpan(currentSnapshot, span)); if (!selection.IsEmpty && selection.Contains(new VirtualSnapshotPoint(triggerPoint.Value))) { applicableToSpan = selection.Snapshot.CreateTrackingSpan(selection.SnapshotSpan, SpanTrackingMode.EdgeExclusive); break; } } } quickInfoContent.Add("Could not parse expression."); } //foreach (var result in finalResult) //{ // quickInfoContent.Add(result); //} #endregion #if false var selection = session.TextView.Selection.StreamSelectionSpan; if (selection.IsEmpty || !selection.Contains(new VirtualSnapshotPoint(triggerPoint.Value))) { SnapshotSpan?expressionSpan = Provider.IntellisenseCache.GetExpressionSpan(triggerPoint.Value); if (expressionSpan.HasValue) { selection = new VirtualSnapshotSpan(expressionSpan.Value); } } #endif //VirtualSnapshotSpan selection = new VirtualSnapshotSpan(); //if (contextSpan.HasValue) // selection = new VirtualSnapshotSpan(contextSpan.Value); //if (!selection.IsEmpty && selection.Contains(new VirtualSnapshotPoint(triggerPoint.Value))) //{ // applicableToSpan = selection.Snapshot.CreateTrackingSpan(selection.SnapshotSpan, SpanTrackingMode.EdgeExclusive); // try // { // Expression currentExpression = Provider.IntellisenseCache.ParseExpression(selection); // if (currentExpression != null) // { // SnapshotSpan? span = currentExpression.Span; // if (span.HasValue) // applicableToSpan = span.Value.Snapshot.CreateTrackingSpan(span.Value, SpanTrackingMode.EdgeExclusive); // quickInfoContent.Add(currentExpression.ToString()); // } // else // { // quickInfoContent.Add("Could not parse expression."); // } // } // catch (Exception ex) // { // if (ErrorHandler.IsCriticalException(ex)) // throw; // quickInfoContent.Add(ex.Message); // } //} } }
public RunCustomToolsCommand(IServiceProvider serviceProvider, EnvDTE.DTE dte, IOutputWindow outputWin) { m_winPane = outputWin.General; m_dte = dte as DTE2; m_serviceProvider = serviceProvider; }
protected override void ReParseImpl() { Stopwatch timer = Stopwatch.StartNew(); // lex the entire document to get the set of identifiers we'll need to classify ITextSnapshot snapshot = TextBuffer.CurrentSnapshot; var input = new SnapshotCharStream(snapshot, new Span(0, snapshot.Length)); JavaUnicodeStream inputWrapper = new JavaUnicodeStream(input); var lexer = new Java2Lexer(inputWrapper); var tokens = new CommonTokenStream(lexer); tokens.Fill(); List <IToken> nameKeywords = new List <IToken>(); List <IToken> declColons = new List <IToken>(); List <IToken> identifiers = new List <IToken>(); HashSet <IToken> definitions = new HashSet <IToken>(TokenIndexEqualityComparer.Default); HashSet <IToken> references = new HashSet <IToken>(TokenIndexEqualityComparer.Default); GetLl2SymbolSets(); while (tokens.LA(1) != CharStreamConstants.EndOfFile) { // covered by the double-sided check if (_definitionOnlySourceSet.Contains(tokens.LA(1))) { if (tokens.LA(2) == Java2Lexer.IDENTIFIER) { definitions.Add(tokens.LT(2)); } } else if (_referenceOnlySourceSet.Contains(tokens.LA(1))) { if (tokens.LA(2) == Java2Lexer.IDENTIFIER) { references.Add(tokens.LT(2)); } } if (_definitionOnlyFollowSet.Contains(tokens.LA(1))) { IToken previous = tokens.LT(-1); if (previous != null && previous.Type == Java2Lexer.IDENTIFIER) { definitions.Add(previous); } } else if (_referenceOnlyFollowSet.Contains(tokens.LA(1))) { IToken previous = tokens.LT(-1); if (previous != null && previous.Type == Java2Lexer.IDENTIFIER) { references.Add(previous); } } if (tokens.LA(2) == Java2Lexer.IDENTIFIER) { IntervalSet bothWaysFollowDefinition; IntervalSet bothWaysFollowReference; _definitionContextSet1.TryGetValue(tokens.LA(1), out bothWaysFollowDefinition); _referenceContextSet1.TryGetValue(tokens.LA(1), out bothWaysFollowReference); bool couldBeDef = bothWaysFollowDefinition != null && bothWaysFollowDefinition.Contains(tokens.LA(3)); bool couldBeRef = bothWaysFollowReference != null && bothWaysFollowReference.Contains(tokens.LA(3)); if (couldBeDef && !couldBeRef) { definitions.Add(tokens.LT(2)); } else if (couldBeRef && !couldBeDef) { references.Add(tokens.LT(2)); } } if (tokens.LA(3) == Java2Lexer.IDENTIFIER && _definitionSourceSet.Contains(tokens.LA(2))) { IntervalSet sourceDefinition2; IntervalSet sourceReference2; _definitionSourceSet2.TryGetValue(tokens.LA(2), out sourceDefinition2); _referenceSourceSet2.TryGetValue(tokens.LA(2), out sourceReference2); bool couldBeDef = sourceDefinition2 != null && sourceDefinition2.Contains(tokens.LA(1)); bool couldBeRef = sourceReference2 != null && sourceReference2.Contains(tokens.LA(1)); if (couldBeDef && !couldBeRef) { definitions.Add(tokens.LT(3)); } else if (couldBeRef && !couldBeDef) { references.Add(tokens.LT(3)); } } if (_definitionFollowSet.Contains(tokens.LA(1))) { declColons.Add(tokens.LT(1)); } if (tokens.LA(1) == Java2Lexer.IDENTIFIER) { identifiers.Add(tokens.LT(1)); } tokens.Consume(); } foreach (var token in declColons) { tokens.Seek(token.TokenIndex); tokens.Consume(); IToken potentialDeclaration = tokens.LT(-2); if (potentialDeclaration.Type != Java2Lexer.IDENTIFIER || definitions.Contains(potentialDeclaration) || references.Contains(potentialDeclaration)) { continue; } bool agree = false; NetworkInterpreter interpreter = CreateVarDeclarationNetworkInterpreter(tokens, token.Type); while (interpreter.TryStepBackward()) { if (interpreter.Contexts.Count == 0 || interpreter.Contexts.Count > 400) { break; } if (interpreter.Contexts.All(context => context.BoundedStart)) { break; } interpreter.Contexts.RemoveAll(i => !IsConsistentWithPreviousResult(i, true, definitions, references)); agree = AllAgree(interpreter.Contexts, potentialDeclaration.TokenIndex); if (agree) { break; } } interpreter.CombineBoundedStartContexts(); if (!agree) { while (interpreter.TryStepForward()) { if (interpreter.Contexts.Count == 0 || interpreter.Contexts.Count > 400) { break; } if (interpreter.Contexts.All(context => context.BoundedEnd)) { break; } interpreter.Contexts.RemoveAll(i => !IsConsistentWithPreviousResult(i, false, definitions, references)); agree = AllAgree(interpreter.Contexts, potentialDeclaration.TokenIndex); if (agree) { break; } } interpreter.CombineBoundedEndContexts(); } foreach (var context in interpreter.Contexts) { foreach (var transition in context.Transitions) { if (!transition.Symbol.HasValue) { continue; } switch (transition.Symbol) { case Java2Lexer.IDENTIFIER: //case Java2Lexer.KW_THIS: RuleBinding rule = interpreter.Network.StateRules[transition.Transition.TargetState.Id]; if (rule.Name == JavaAtnBuilder.RuleNames.SymbolReferenceIdentifier) { references.Add(tokens.Get(transition.TokenIndex.Value)); } else if (rule.Name == JavaAtnBuilder.RuleNames.SymbolDefinitionIdentifier) { definitions.Add(tokens.Get(transition.TokenIndex.Value)); } break; default: continue; } } } } // tokens which are in both the 'definitions' and 'references' sets are actually unknown. HashSet <IToken> unknownIdentifiers = new HashSet <IToken>(definitions, TokenIndexEqualityComparer.Default); unknownIdentifiers.IntersectWith(references); definitions.ExceptWith(unknownIdentifiers); #if true // set to true to mark all unknown identifiers as references (requires complete analysis of definitions) references = new HashSet <IToken>(identifiers, TokenIndexEqualityComparer.Default); references.ExceptWith(definitions); references.ExceptWith(unknownIdentifiers); #else references.ExceptWith(unknownIdentifiers); // the full set of unknown identifiers are any that aren't explicitly classified as a definition or a reference unknownIdentifiers = new HashSet <IToken>(identifiers, TokenIndexEqualityComparer.Default); unknownIdentifiers.ExceptWith(definitions); unknownIdentifiers.ExceptWith(references); #endif List <ITagSpan <IClassificationTag> > tags = new List <ITagSpan <IClassificationTag> >(); IClassificationType definitionClassificationType = _classificationTypeRegistryService.GetClassificationType(JavaSymbolTaggerClassificationTypeNames.Definition); tags.AddRange(ClassifyTokens(snapshot, definitions, new ClassificationTag(definitionClassificationType))); IClassificationType referenceClassificationType = _classificationTypeRegistryService.GetClassificationType(JavaSymbolTaggerClassificationTypeNames.Reference); tags.AddRange(ClassifyTokens(snapshot, references, new ClassificationTag(referenceClassificationType))); IClassificationType unknownClassificationType = _classificationTypeRegistryService.GetClassificationType(JavaSymbolTaggerClassificationTypeNames.UnknownIdentifier); tags.AddRange(ClassifyTokens(snapshot, unknownIdentifiers, new ClassificationTag(unknownClassificationType))); _tags = tags; timer.Stop(); IOutputWindowPane pane = OutputWindowService.TryGetPane(PredefinedOutputWindowPanes.TvlIntellisense); if (pane != null) { pane.WriteLine(string.Format("Finished classifying {0} identifiers in {1}ms: {2} definitions, {3} references, {4} unknown", identifiers.Count, timer.ElapsedMilliseconds, definitions.Count, references.Count, unknownIdentifiers.Count)); } OnTagsChanged(new SnapshotSpanEventArgs(new SnapshotSpan(snapshot, new Span(0, snapshot.Length)))); }