public override void EnterClassOrInterfaceDefinition(PhpParser.ClassOrInterfaceDefinitionContext context) { string name = GetQualifiedName(context); IEditorNavigationType navigationType = _provider.EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Types); var startToken = _antlrParseResultArgs.Tokens[context.SourceInterval.a]; var stopToken = _antlrParseResultArgs.Tokens[context.SourceInterval.b]; SnapshotSpan span = new SnapshotSpan(_snapshot, new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1)); SnapshotSpan seek = span; if (context.PHP_IDENTIFIER() != null) { seek = new SnapshotSpan(_snapshot, new Span(context.PHP_IDENTIFIER().Symbol.StartIndex, 0)); } StandardGlyphGroup glyphGroup; if (context.KW_INTERFACE() != null) { glyphGroup = StandardGlyphGroup.GlyphGroupInterface; } else { glyphGroup = StandardGlyphGroup.GlyphGroupClass; } //StandardGlyphItem glyphItem = GetGlyphItemFromChildModifier(child); StandardGlyphItem glyphItem = StandardGlyphItem.GlyphItemPublic; ImageSource glyph = _provider.GlyphService.GetGlyph(glyphGroup, glyphItem); NavigationTargetStyle style = NavigationTargetStyle.None; _navigationTargets.Add(new EditorNavigationTarget(name, navigationType, span, seek, glyph, style)); }
public Antlr4EditorNavigationSource([NotNull] Antlr4EditorNavigationSourceProvider provider, [NotNull] ITextBuffer textBuffer) { Requires.NotNull(provider, nameof(provider)); Requires.NotNull(textBuffer, nameof(textBuffer)); _provider = provider; _textBuffer = textBuffer; _parserRuleNavigationType = provider.EditorNavigationTypeRegistryService.GetEditorNavigationType(AntlrEditorNavigationTypeNames.ParserRule); _lexerRuleNavigationType = provider.EditorNavigationTypeRegistryService.GetEditorNavigationType(AntlrEditorNavigationTypeNames.LexerRule); string assemblyName = typeof(Antlr4EditorNavigationSource).Assembly.GetName().Name; _lexerRuleGlyph = new BitmapImage(new Uri(string.Format("pack://application:,,,/{0};component/Resources/lexericon.png", assemblyName))); _parserRuleGlyph = new BitmapImage(new Uri(string.Format("pack://application:,,,/{0};component/Resources/parsericon.png", assemblyName))); _backgroundParser = (Antlr4BackgroundParser)provider.BackgroundParserFactoryService.GetBackgroundParser(textBuffer); _backgroundParser.ParseComplete += HandleBackgroundParseComplete; _backgroundParser.RequestParse(false); var lastParseResult = _backgroundParser.LastResult; if (lastParseResult != null) { UpdateNavigationTargets(lastParseResult); } }
private void UpdateNavigationTargets([NotNull] IEnumerable <IEditorNavigationTarget> targets) { Requires.NotNull(targets, nameof(targets)); foreach (var group in targets.GroupBy(target => target.EditorNavigationType)) { var navigationControl = this._navigationControls.FirstOrDefault(control => control.Item1 == group.Key); if (navigationControl == null) { continue; } var combo = navigationControl.Item2; combo.Items.Clear(); foreach (var item in group.OrderBy(i => i.Name, StringComparer.CurrentCultureIgnoreCase)) { combo.Items.Add(item); } } _owners.Clear(); foreach (var childControl in _navigationControls) { IEditorNavigationType navigationType = childControl.Item1; string enclosingType = navigationType.Definition.EnclosingTypes.FirstOrDefault(); if (string.IsNullOrEmpty(enclosingType)) { continue; } foreach (var childItem in childControl.Item2.Items.OfType <IEditorNavigationTarget>()) { foreach (var control in _navigationControls.Where(i => i.Item1.IsOfType(enclosingType))) { IEditorNavigationTarget best = control.Item2.Items.Cast <IEditorNavigationTarget>() .Where(i => i.Span.OverlapsWith(childItem.Span)) .OrderBy(i => i.Span.Length) .FirstOrDefault(); if (best != null) { _owners[childItem] = best; goto nextChild; } } nextChild: continue; } } UpdateSelectedNavigationTargets(); }
public EditorNavigationTarget([NotNull] string name, [NotNull] IEditorNavigationType editorNavigationType, SnapshotSpan span, SnapshotSpan seek, ImageSource glyph = null, NavigationTargetStyle style = NavigationTargetStyle.None) { Requires.NotNull(name, nameof(name)); Requires.NotNull(editorNavigationType, nameof(editorNavigationType)); this._name = name; this._editorNavigationType = editorNavigationType; this.Span = span; this.Seek = seek; this._style = style; this.Glyph = glyph; }
public EditorNavigationTarget(string name, IEditorNavigationType editorNavigationType, SnapshotSpan span, SnapshotSpan seek, ImageSource glyph = null, NavigationTargetStyle style = NavigationTargetStyle.None) { Contract.Requires<ArgumentNullException>(name != null, "name"); Contract.Requires<ArgumentNullException>(editorNavigationType != null, "editorNavigationType"); this._name = name; this._editorNavigationType = editorNavigationType; this.Span = span; this.Seek = seek; this._style = style; this.Glyph = glyph; }
public EditorNavigationTarget(string name, IEditorNavigationType editorNavigationType, SnapshotSpan span, SnapshotSpan seek, ImageSource glyph = null, NavigationTargetStyle style = NavigationTargetStyle.None) { Contract.Requires <ArgumentNullException>(name != null, "name"); Contract.Requires <ArgumentNullException>(editorNavigationType != null, "editorNavigationType"); this._name = name; this._editorNavigationType = editorNavigationType; this.Span = span; this.Seek = seek; this._style = style; this.Glyph = glyph; }
public Antlr4EditorNavigationSource(Antlr4EditorNavigationSourceProvider provider, ITextBuffer textBuffer) { Contract.Requires<ArgumentNullException>(provider != null, "provider"); Contract.Requires<ArgumentNullException>(textBuffer != null, "textBuffer"); _provider = provider; _textBuffer = textBuffer; _parserRuleNavigationType = provider.EditorNavigationTypeRegistryService.GetEditorNavigationType(AntlrEditorNavigationTypeNames.ParserRule); _lexerRuleNavigationType = provider.EditorNavigationTypeRegistryService.GetEditorNavigationType(AntlrEditorNavigationTypeNames.LexerRule); string assemblyName = typeof(Antlr4EditorNavigationSource).Assembly.GetName().Name; _lexerRuleGlyph = new BitmapImage(new Uri(string.Format("pack://application:,,,/{0};component/Resources/lexericon.png", assemblyName))); _parserRuleGlyph = new BitmapImage(new Uri(string.Format("pack://application:,,,/{0};component/Resources/parsericon.png", assemblyName))); _backgroundParser = (Antlr4BackgroundParser)provider.BackgroundParserFactoryService.GetBackgroundParser(textBuffer); _backgroundParser.ParseComplete += HandleBackgroundParseComplete; _backgroundParser.RequestParse(false); }
public AntlrEditorNavigationSource(ITextBuffer textBuffer, AntlrBackgroundParser backgroundParser, IEditorNavigationTypeRegistryService editorNavigationTypeRegistryService) { Contract.Requires<ArgumentNullException>(textBuffer != null, "textBuffer"); Contract.Requires<ArgumentNullException>(backgroundParser != null, "backgroundParser"); Contract.Requires<ArgumentNullException>(editorNavigationTypeRegistryService != null, "editorNavigationTypeRegistryService"); this.TextBuffer = textBuffer; this.BackgroundParser = backgroundParser; this.EditorNavigationTypeRegistryService = editorNavigationTypeRegistryService; this._parserRuleNavigationType = this.EditorNavigationTypeRegistryService.GetEditorNavigationType(AntlrEditorNavigationTypeNames.ParserRule); this._lexerRuleNavigationType = this.EditorNavigationTypeRegistryService.GetEditorNavigationType(AntlrEditorNavigationTypeNames.LexerRule); string assemblyName = typeof(AntlrEditorNavigationSource).Assembly.GetName().Name; this._lexerRuleGlyph = new BitmapImage(new Uri(string.Format("pack://application:,,,/{0};component/Resources/lexericon.png", assemblyName))); this._parserRuleGlyph = new BitmapImage(new Uri(string.Format("pack://application:,,,/{0};component/Resources/parsericon.png", assemblyName))); this.BackgroundParser.ParseComplete += HandleBackgroundParseComplete; this.BackgroundParser.RequestParse(false); }
public Antlr4EditorNavigationSource(Antlr4EditorNavigationSourceProvider provider, ITextBuffer textBuffer) { Contract.Requires <ArgumentNullException>(provider != null, "provider"); Contract.Requires <ArgumentNullException>(textBuffer != null, "textBuffer"); _provider = provider; _textBuffer = textBuffer; _parserRuleNavigationType = provider.EditorNavigationTypeRegistryService.GetEditorNavigationType(AntlrEditorNavigationTypeNames.ParserRule); _lexerRuleNavigationType = provider.EditorNavigationTypeRegistryService.GetEditorNavigationType(AntlrEditorNavigationTypeNames.LexerRule); string assemblyName = typeof(Antlr4EditorNavigationSource).Assembly.GetName().Name; _lexerRuleGlyph = new BitmapImage(new Uri(string.Format("pack://application:,,,/{0};component/Resources/lexericon.png", assemblyName))); _parserRuleGlyph = new BitmapImage(new Uri(string.Format("pack://application:,,,/{0};component/Resources/parsericon.png", assemblyName))); _backgroundParser = (Antlr4BackgroundParser)provider.BackgroundParserFactoryService.GetBackgroundParser(textBuffer); _backgroundParser.ParseComplete += HandleBackgroundParseComplete; _backgroundParser.RequestParse(false); }
public AntlrEditorNavigationSource(ITextBuffer textBuffer, AntlrBackgroundParser backgroundParser, IEditorNavigationTypeRegistryService editorNavigationTypeRegistryService) { Contract.Requires <ArgumentNullException>(textBuffer != null, "textBuffer"); Contract.Requires <ArgumentNullException>(backgroundParser != null, "backgroundParser"); Contract.Requires <ArgumentNullException>(editorNavigationTypeRegistryService != null, "editorNavigationTypeRegistryService"); this.TextBuffer = textBuffer; this.BackgroundParser = backgroundParser; this.EditorNavigationTypeRegistryService = editorNavigationTypeRegistryService; this._parserRuleNavigationType = this.EditorNavigationTypeRegistryService.GetEditorNavigationType(AntlrEditorNavigationTypeNames.ParserRule); this._lexerRuleNavigationType = this.EditorNavigationTypeRegistryService.GetEditorNavigationType(AntlrEditorNavigationTypeNames.LexerRule); string assemblyName = typeof(AntlrEditorNavigationSource).Assembly.GetName().Name; this._lexerRuleGlyph = new BitmapImage(new Uri(string.Format("pack://application:,,,/{0};component/Resources/lexericon.png", assemblyName))); this._parserRuleGlyph = new BitmapImage(new Uri(string.Format("pack://application:,,,/{0};component/Resources/parsericon.png", assemblyName))); this.BackgroundParser.ParseComplete += HandleBackgroundParseComplete; this.BackgroundParser.RequestParse(false); }
private bool ComboBoxFilter(IEditorNavigationType navigationType, EditorNavigationComboBox comboBox, IEditorNavigationTarget target) { if (navigationType == null || comboBox == null || target == null) { return(true); } if (!navigationType.Definition.EnclosingTypes.Any()) { return(true); } IEditorNavigationTarget owner; if (!_owners.TryGetValue(target, out owner)) { return(true); } return(_navigationControls.Select(i => i.Item2.SelectedItem).OfType <IEditorNavigationTarget>().Contains(owner)); }
private bool ComboBoxFilter(IEditorNavigationType navigationType, List <IEditorNavigationTarget> comboBox, IEditorNavigationTarget target) { if (navigationType == null || comboBox == null || target == null) { return(true); } if (!navigationType.Definition.EnclosingTypes.Any()) { return(true); } IEditorNavigationTarget owner; if (!_owners.TryGetValue(target, out owner)) { return(true); } return(_selectedItem.Contains(owner)); }
public AntlrEditorNavigationSource([NotNull] ITextBuffer textBuffer, [NotNull] AntlrBackgroundParser backgroundParser, [NotNull] IEditorNavigationTypeRegistryService editorNavigationTypeRegistryService) { Requires.NotNull(textBuffer, nameof(textBuffer)); Requires.NotNull(backgroundParser, nameof(backgroundParser)); Requires.NotNull(editorNavigationTypeRegistryService, nameof(editorNavigationTypeRegistryService)); this.TextBuffer = textBuffer; this.BackgroundParser = backgroundParser; this.EditorNavigationTypeRegistryService = editorNavigationTypeRegistryService; this._parserRuleNavigationType = this.EditorNavigationTypeRegistryService.GetEditorNavigationType(AntlrEditorNavigationTypeNames.ParserRule); this._lexerRuleNavigationType = this.EditorNavigationTypeRegistryService.GetEditorNavigationType(AntlrEditorNavigationTypeNames.LexerRule); string assemblyName = typeof(AntlrEditorNavigationSource).Assembly.GetName().Name; this._lexerRuleGlyph = new BitmapImage(new Uri(string.Format("pack://application:,,,/{0};component/Resources/lexericon.png", assemblyName))); this._parserRuleGlyph = new BitmapImage(new Uri(string.Format("pack://application:,,,/{0};component/Resources/parsericon.png", assemblyName))); this.BackgroundParser.ParseComplete += HandleBackgroundParseComplete; this.BackgroundParser.RequestParse(false); }
public override void EnterFunctionDefinition(PhpParser.FunctionDefinitionContext context) { string name = GetName(context); IEnumerable <string> args = ProcessArguments(context.functionParameterList()); string sig = string.Format("{0}({1})", name, string.Join(", ", args)); IEditorNavigationType navigationType = _provider.EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Members); var startToken = _antlrParseResultArgs.Tokens[context.SourceInterval.a]; var stopToken = _antlrParseResultArgs.Tokens[context.SourceInterval.b]; SnapshotSpan span = new SnapshotSpan(_snapshot, new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1)); SnapshotSpan seek = span; if (context.PHP_IDENTIFIER() != null) { seek = new SnapshotSpan(_snapshot, new Span(context.PHP_IDENTIFIER().Symbol.StartIndex, 0)); } StandardGlyphGroup glyphGroup = StandardGlyphGroup.GlyphGroupMethod; //StandardGlyphItem glyphItem = GetGlyphItemFromChildModifier(tree); StandardGlyphItem glyphItem = StandardGlyphItem.GlyphItemPublic; ImageSource glyph = _provider.GlyphService.GetGlyph(glyphGroup, glyphItem); NavigationTargetStyle style = NavigationTargetStyle.None; _navigationTargets.Add(new EditorNavigationTarget(sig, navigationType, span, seek, glyph, style)); }
public EditorNavigationTarget([NotNull] string name, [NotNull] IEditorNavigationType editorNavigationType, SnapshotSpan span, ImageSource glyph = null, NavigationTargetStyle style = NavigationTargetStyle.None) : this(name, editorNavigationType, span, new SnapshotSpan(span.Start, span.End), glyph, style) { Debug.Assert(name != null); Debug.Assert(editorNavigationType != null); }
public EditorNavigationTarget(string name, IEditorNavigationType editorNavigationType, SnapshotSpan span, ImageSource glyph = null, NavigationTargetStyle style = NavigationTargetStyle.None) : this(name, editorNavigationType, span, new SnapshotSpan(span.Start, span.End), glyph, style) { Contract.Requires(name != null); Contract.Requires(editorNavigationType != null); }
private void HandleBackgroundParseComplete(object sender, ParseResultEventArgs e) { List <IEditorNavigationTarget> navigationTargets = new List <IEditorNavigationTarget>(); AntlrParseResultEventArgs antlrParseResultArgs = e as AntlrParseResultEventArgs; if (antlrParseResultArgs != null) { var result = antlrParseResultArgs.Result as StringTemplateBackgroundParser.TemplateGroupRuleReturnScope; if (result != null) { foreach (var templateInfo in result.Group.GetTemplateInformation()) { Antlr4.StringTemplate.Compiler.CompiledTemplate template = templateInfo.Template; if (template.IsAnonSubtemplate) { continue; } bool isRegion = !string.IsNullOrEmpty(templateInfo.EnclosingTemplateName); if (isRegion) { string sig = string.Format("{0}.{1}()", templateInfo.EnclosingTemplateName, templateInfo.NameToken.Text); //string sig = string.Format("{0}({1})", name, string.Join(", ", args)); IEditorNavigationType navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(StringTemplateEditorNavigationTypes.Templates); Interval sourceInterval = templateInfo.GroupInterval; SnapshotSpan span = new SnapshotSpan(e.Snapshot, new Span(sourceInterval.Start, sourceInterval.Length)); SnapshotSpan seek = new SnapshotSpan(e.Snapshot, new Span(sourceInterval.Start, 0)); ImageSource glyph = _provider.GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupNamespace, StandardGlyphItem.GlyphItemPublic); NavigationTargetStyle style = NavigationTargetStyle.None; navigationTargets.Add(new EditorNavigationTarget(sig, navigationType, span, seek, glyph, style)); } else { // always pull the name from the templateInfo because the template itself could be an aliased template string name = templateInfo.NameToken.Text; IEnumerable <string> args = template.FormalArguments != null?template.FormalArguments.Select(i => i.Name) : Enumerable.Empty <string>(); string sig = string.Format("{0}({1})", name, string.Join(", ", args)); IEditorNavigationType navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(StringTemplateEditorNavigationTypes.Templates); Interval sourceInterval = templateInfo.GroupInterval; SnapshotSpan span = new SnapshotSpan(e.Snapshot, new Span(sourceInterval.Start, sourceInterval.Length)); SnapshotSpan seek = new SnapshotSpan(e.Snapshot, new Span(sourceInterval.Start, 0)); bool isAlias = false; StandardGlyphGroup glyphGroup = isAlias ? StandardGlyphGroup.GlyphGroupTypedef : StandardGlyphGroup.GlyphGroupTemplate; ImageSource glyph = _provider.GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupTemplate, StandardGlyphItem.GlyphItemPublic); NavigationTargetStyle style = NavigationTargetStyle.None; navigationTargets.Add(new EditorNavigationTarget(sig, navigationType, span, seek, glyph, style)); } } //foreach (var dictionaryInfo in result.Group.GetDictionaryInformation()) //{ // string name = dictionaryInfo.Name; // IEditorNavigationType navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Members); // Interval sourceInterval = dictionaryInfo.GroupInterval; // SnapshotSpan span = new SnapshotSpan(e.Snapshot, new Span(sourceInterval.Start, sourceInterval.Length)); // SnapshotSpan seek = new SnapshotSpan(e.Snapshot, new Span(sourceInterval.Start, 0)); // ImageSource glyph = _provider.GetGlyph(StandardGlyphGroup.GlyphGroupModule, StandardGlyphItem.GlyphItemPublic); // NavigationTargetStyle style = NavigationTargetStyle.None; // navigationTargets.Add(new EditorNavigationTarget(sig, navigationType, span, seek, glyph, style)); //} } } this._navigationTargets = navigationTargets; OnNavigationTargetsChanged(EventArgs.Empty); }
private void AddNavigationTarget(IParseTree tree, ITerminalNode identifier, IEditorNavigationType navigationType, ImageSource glyph) { Contract.Requires(tree != null); Contract.Requires(navigationType != null); Interval sourceInterval = tree.SourceInterval; if (sourceInterval.a < 0 || sourceInterval.b < 0 || sourceInterval.Length <= 0) { return; } IToken startToken = _tokens[sourceInterval.a]; IToken stopToken = _tokens[sourceInterval.b]; Span span = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1); Span seek; string name = identifier != null?identifier.GetText() : null; if (string.IsNullOrEmpty(name)) { seek = new Span(span.Start, 0); name = "?"; } else { seek = new Span(identifier.Symbol.StartIndex, 0); } if (_mode.Count > 0) { name = _mode.Peek() + "." + name; } _navigationTargets.Add(new EditorNavigationTarget(name, navigationType, new SnapshotSpan(_snapshot, span), new SnapshotSpan(_snapshot, seek), glyph)); }
private bool ComboBoxFilter(IEditorNavigationType navigationType, EditorNavigationComboBox comboBox, IEditorNavigationTarget target) { if (navigationType == null || comboBox == null || target == null) return true; if (!navigationType.Definition.EnclosingTypes.Any()) return true; IEditorNavigationTarget owner; if (!_owners.TryGetValue(target, out owner)) return true; return _navigationControls.Select(i => i.Item2.SelectedItem).OfType<IEditorNavigationTarget>().Contains(owner); }
private bool ComboBoxFilter(IEditorNavigationType navigationType, List<IEditorNavigationTarget> comboBox, IEditorNavigationTarget target) { if (navigationType == null || comboBox == null || target == null) return true; if (!navigationType.Definition.EnclosingTypes.Any()) return true; IEditorNavigationTarget owner; if (!_owners.TryGetValue(target, out owner)) return true; return _selectedItem.Contains(owner); }
private void UpdateTags(AntlrParseResultEventArgs antlrParseResultArgs) { List <IEditorNavigationTarget> navigationTargets = new List <IEditorNavigationTarget>(); IAstRuleReturnScope resultArgs = antlrParseResultArgs.Result as IAstRuleReturnScope; var result = resultArgs != null ? resultArgs.Tree as CommonTree : null; if (result != null) { ITextSnapshot snapshot = antlrParseResultArgs.Snapshot; string package = string.Empty; /* ^('package' qualifiedName) * * ^(CLASS_TYPE_IDENTIFIER modifiers .* ^(TYPE_BODY .* '}')) * * ^(INTERFACE_TYPE_IDENTIFIER modifiers .* ^(TYPE_BODY .* '}')) * * ^(ANNOTATION_TYPE_IDENTIFIER modifiers .* ^(TYPE_BODY .* '}')) * * ^(FIELD_DECLARATION modifiers (.* ^(VARIABLE_IDENTIFIER .*))*) * * ^(METHOD_IDENTIFIER modifiers .* ^(FORMAL_PARAMETERS .* ')') .* ^(METHOD_BODY .* '}')) */ /* STATEMENT COMPLETION (description unrelated to this file) * * IDENTIFIER ('.' IDENTIFIER)* * * ^(CALL IDENTIFIER .*) * * ^('(' ^('==' .*) ')') * */ for (CommonTreeNodeStream treeNodeStream = new CommonTreeNodeStream(result); treeNodeStream.LA(1) != CharStreamConstants.EndOfFile; treeNodeStream.Consume()) { switch (treeNodeStream.LA(1)) { case Java2Lexer.PACKAGE: // ^('package' qualifiedName) { CommonTree child = treeNodeStream.LT(1) as CommonTree; if (child != null && child.ChildCount > 0) { package = GetQualifiedIdentifier(child.GetChild(0)); } } break; case Java2Lexer.VARIABLE_IDENTIFIER: // ^(FIELD_DECLARATION (.* ^(VARIABLE_IDENTIFIER))*) { CommonTree child = treeNodeStream.LT(1) as CommonTree; if (child != null && child.HasAncestor(Java2Lexer.FIELD_DECLARATION)) { string name = child.Token.Text; IEditorNavigationType navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Members); var startToken = antlrParseResultArgs.Tokens[child.TokenStartIndex]; var stopToken = antlrParseResultArgs.Tokens[child.TokenStopIndex]; SnapshotSpan span = new SnapshotSpan(snapshot, new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1)); SnapshotSpan seek = new SnapshotSpan(snapshot, new Span(child.Token.StartIndex, 0)); StandardGlyphGroup glyphGroup = StandardGlyphGroup.GlyphGroupJSharpField; StandardGlyphItem glyphItem = GetGlyphItemFromChildModifier((CommonTree)child.GetAncestor(Java2Lexer.FIELD_DECLARATION)); ImageSource glyph = _provider.GlyphService.GetGlyph(glyphGroup, glyphItem); NavigationTargetStyle style = NavigationTargetStyle.None; navigationTargets.Add(new EditorNavigationTarget(name, navigationType, span, seek, glyph, style)); } } break; case Java2Lexer.METHOD_IDENTIFIER: // ^(METHOD_IDENTIFIER ^(FORMAL_PARAMETERS formalParameterDecls?) ^(METHOD_BODY .* END_METHOD_BODY)) { CommonTree child = treeNodeStream.LT(1) as CommonTree; if (child != null) { string name = child.Token.Text; IEnumerable <string> args = ProcessArguments((CommonTree)child.GetFirstChildWithType(Java2Lexer.FORMAL_PARAMETERS)); string sig = string.Format("{0}({1})", name, string.Join(", ", args)); IEditorNavigationType navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Members); var startToken = antlrParseResultArgs.Tokens[child.TokenStartIndex]; var stopToken = antlrParseResultArgs.Tokens[child.TokenStopIndex]; SnapshotSpan span = new SnapshotSpan(snapshot, new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1)); SnapshotSpan seek = new SnapshotSpan(snapshot, new Span(child.Token.StartIndex, 0)); StandardGlyphGroup glyphGroup = StandardGlyphGroup.GlyphGroupJSharpMethod; StandardGlyphItem glyphItem = GetGlyphItemFromChildModifier(child); ImageSource glyph = _provider.GlyphService.GetGlyph(glyphGroup, glyphItem); NavigationTargetStyle style = NavigationTargetStyle.None; navigationTargets.Add(new EditorNavigationTarget(sig, navigationType, span, seek, glyph, style)); } } break; case Java2Lexer.ENUM_TYPE_IDENTIFIER: case Java2Lexer.ANNOTATION_TYPE_IDENTIFIER: case Java2Lexer.INTERFACE_TYPE_IDENTIFIER: case Java2Lexer.CLASS_TYPE_IDENTIFIER: { CommonTree child = treeNodeStream.LT(1) as CommonTree; if (child != null) { string name = child.Token.Text; for (ITree parent = child.Parent; parent != null; parent = parent.Parent) { switch (parent.Type) { case Java2Lexer.ENUM_TYPE_IDENTIFIER: case Java2Lexer.ANNOTATION_TYPE_IDENTIFIER: case Java2Lexer.INTERFACE_TYPE_IDENTIFIER: case Java2Lexer.CLASS_TYPE_IDENTIFIER: name = parent.Text + "." + name; continue; default: continue; } } if (!string.IsNullOrEmpty(package)) { name = package + "." + name; } IEditorNavigationType navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Types); var startToken = antlrParseResultArgs.Tokens[child.TokenStartIndex]; var stopToken = antlrParseResultArgs.Tokens[child.TokenStopIndex]; SnapshotSpan span = new SnapshotSpan(snapshot, new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1)); SnapshotSpan seek = new SnapshotSpan(snapshot, new Span(child.Token.StartIndex, 0)); StandardGlyphGroup glyphGroup; switch (child.Type) { case Java2Lexer.ENUM_TYPE_IDENTIFIER: glyphGroup = StandardGlyphGroup.GlyphGroupEnum; break; case Java2Lexer.ANNOTATION_TYPE_IDENTIFIER: case Java2Lexer.INTERFACE_TYPE_IDENTIFIER: glyphGroup = StandardGlyphGroup.GlyphGroupJSharpInterface; break; case Java2Lexer.CLASS_TYPE_IDENTIFIER: default: glyphGroup = StandardGlyphGroup.GlyphGroupJSharpClass; break; } StandardGlyphItem glyphItem = GetGlyphItemFromChildModifier(child); ImageSource glyph = _provider.GlyphService.GetGlyph(glyphGroup, glyphItem); NavigationTargetStyle style = NavigationTargetStyle.None; navigationTargets.Add(new EditorNavigationTarget(name, navigationType, span, seek, glyph, style)); } } break; default: continue; } } } this._navigationTargets = navigationTargets; OnNavigationTargetsChanged(EventArgs.Empty); }
private void UpdateNavigationTargets([NotNull] PhpEditorNavigationParseResultEventArgs antlrParseResultArgs) { Debug.Assert(antlrParseResultArgs != null); List <IEditorNavigationTarget> navigationTargets = new List <IEditorNavigationTarget>(); // always add the "global scope" element { string name = "Global Scope"; IEditorNavigationType editorNavigationType = Provider.EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Types); SnapshotSpan span = new SnapshotSpan(antlrParseResultArgs.Snapshot, 0, antlrParseResultArgs.Snapshot.Length); SnapshotSpan seek = new SnapshotSpan(span.Start, 0); ImageSource glyph = Provider.GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupNamespace, StandardGlyphItem.GlyphItemPublic); NavigationTargetStyle style = NavigationTargetStyle.None; navigationTargets.Add(new EditorNavigationTarget(name, editorNavigationType, span, seek, glyph, style)); } if (antlrParseResultArgs != null) { ITextSnapshot snapshot = antlrParseResultArgs.Snapshot; Listener listener = new Listener(Provider, snapshot, antlrParseResultArgs, navigationTargets); foreach (var tree in antlrParseResultArgs.NavigationTrees) { ParseTreeWalkers.SingleTree.Walk(listener, tree); } #if false IAstRuleReturnScope resultArgs = antlrParseResultArgs.Result as IAstRuleReturnScope; var result = resultArgs != null ? resultArgs.Tree as CommonTree : null; if (result != null) { foreach (CommonTree child in result.Children) { if (child == null || string.IsNullOrEmpty(child.Text)) { continue; } if (child.Text == "rule" && child.ChildCount > 0) { var ruleName = child.GetChild(0).Text; if (string.IsNullOrEmpty(ruleName)) { continue; } if (ruleName == "Tokens") { continue; } var navigationType = char.IsUpper(ruleName[0]) ? _lexerRuleNavigationType : _parserRuleNavigationType; IToken startToken = antlrParseResultArgs.Tokens[child.TokenStartIndex]; IToken stopToken = antlrParseResultArgs.Tokens[child.TokenStopIndex]; Span span = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1); SnapshotSpan ruleSpan = new SnapshotSpan(antlrParseResultArgs.Snapshot, span); SnapshotSpan ruleSeek = new SnapshotSpan(antlrParseResultArgs.Snapshot, new Span(((CommonTree)child.GetChild(0)).Token.StartIndex, 0)); var glyph = char.IsUpper(ruleName[0]) ? _lexerRuleGlyph : _parserRuleGlyph; navigationTargets.Add(new EditorNavigationTarget(ruleName, navigationType, ruleSpan, ruleSeek, glyph)); } else if (child.Text.StartsWith("tokens")) { foreach (CommonTree tokenChild in child.Children) { if (tokenChild.Text == "=" && tokenChild.ChildCount == 2) { var ruleName = tokenChild.GetChild(0).Text; if (string.IsNullOrEmpty(ruleName)) { continue; } var navigationType = char.IsUpper(ruleName[0]) ? _lexerRuleNavigationType : _parserRuleNavigationType; IToken startToken = antlrParseResultArgs.Tokens[tokenChild.TokenStartIndex]; IToken stopToken = antlrParseResultArgs.Tokens[tokenChild.TokenStopIndex]; Span span = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1); SnapshotSpan ruleSpan = new SnapshotSpan(antlrParseResultArgs.Snapshot, span); SnapshotSpan ruleSeek = new SnapshotSpan(antlrParseResultArgs.Snapshot, new Span(((CommonTree)tokenChild.GetChild(0)).Token.StartIndex, 0)); var glyph = char.IsUpper(ruleName[0]) ? _lexerRuleGlyph : _parserRuleGlyph; navigationTargets.Add(new EditorNavigationTarget(ruleName, navigationType, ruleSpan, ruleSeek, glyph)); } else if (tokenChild.ChildCount == 0) { var ruleName = tokenChild.Text; if (string.IsNullOrEmpty(ruleName)) { continue; } var navigationType = char.IsUpper(ruleName[0]) ? _lexerRuleNavigationType : _parserRuleNavigationType; IToken startToken = antlrParseResultArgs.Tokens[tokenChild.TokenStartIndex]; IToken stopToken = antlrParseResultArgs.Tokens[tokenChild.TokenStopIndex]; Span span = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1); SnapshotSpan ruleSpan = new SnapshotSpan(antlrParseResultArgs.Snapshot, span); SnapshotSpan ruleSeek = new SnapshotSpan(antlrParseResultArgs.Snapshot, new Span(tokenChild.Token.StartIndex, 0)); var glyph = char.IsUpper(ruleName[0]) ? _lexerRuleGlyph : _parserRuleGlyph; navigationTargets.Add(new EditorNavigationTarget(ruleName, navigationType, ruleSpan, ruleSeek, glyph)); } } } } } #endif } this._navigationTargets = navigationTargets; OnNavigationTargetsChanged(EventArgs.Empty); }
private void AddNavigationTarget(IParseTree tree, ITerminalNode identifier, IEditorNavigationType navigationType, ImageSource glyph) { Contract.Requires(tree != null); Contract.Requires(navigationType != null); Interval sourceInterval = tree.SourceInterval; if (sourceInterval.a < 0 || sourceInterval.b < 0 || sourceInterval.Length <= 0) return; IToken startToken = _tokens[sourceInterval.a]; IToken stopToken = _tokens[sourceInterval.b]; Span span = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1); Span seek; string name = identifier != null ? identifier.GetText() : null; if (string.IsNullOrEmpty(name)) { seek = new Span(span.Start, 0); name = "?"; } else { seek = new Span(identifier.Symbol.StartIndex, 0); } if (_mode.Count > 0) { name = _mode.Peek() + "." + name; } _navigationTargets.Add(new EditorNavigationTarget(name, navigationType, new SnapshotSpan(_snapshot, span), new SnapshotSpan(_snapshot, seek), glyph)); }