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 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 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 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(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 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 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); }
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); }