private string getQuickInfo(IMappingTagSpan <StaDynTokenTag> curTag, StaDynSourceFileAST parseResult) { var tagSpan = curTag.Span.GetSpans(_buffer).First(); int line = curTag.Tag.StaDynToken.getLine() + 1; //column = curTag.Tag.StaDynToken.getColumn() - curTag.Tag.StaDynToken.getText().Length + 1; int column = curTag.Tag.StaDynToken.getColumn(); //foundNode = (AstNode)parseResult.Ast.Accept(new VisitorFindNode(), new Location(Path.GetFileName(parseResult.FileName), line, column)); var foundNode = (AstNode)parseResult.Ast.Accept(new VisitorFindNode(), new Location(parseResult.FileName, line, column)); //Gets the Node Type TypeExpression type = (TypeExpression)foundNode.AcceptOperation(new GetNodeTypeOperation(), null); //Show the token name string output = curTag.Tag.StaDynToken.getText() + ": "; if (type != null) { output += type.FullName; //output +=type.AcceptOperation(new GetTypeSystemName(), null) as string; } else { output += foundNode.GetType().FullName; } return(output); }
public VarPath getVarPath(string varName, int line, int column, StaDynSourceFileAST file) { if (file == null || file.Ast == null) { return(null); } return(this.getVarPath(varName, line, column, file.Ast)); ////Location currentLocation = new Location(Path.GetFileName(file.FileName), line + 1, column); //Location currentLocation = new Location(file.FileName, line + 1, column); //Namespace currentNamespace = StaDynIntellisenseHelper.Instance.getCurrentNameSpace(currentLocation, file.Ast); //ClassDefinition currentClass = StaDynIntellisenseHelper.Instance.getCurrentClass(currentLocation, file.Ast); //MethodDefinition currentMethod = StaDynIntellisenseHelper.Instance.getCurrentMethod(currentLocation, file.Ast); //VarPath varpath = new VarPath(); //varpath.VarName = varName; //varpath.NamespaceName = currentNamespace != null ? currentNamespace.Identifier.Identifier : ""; //varpath.ClassName = currentClass != null ? currentClass.Identifier : null; //varpath.MethodName = currentMethod != null ? currentMethod.Identifier : null; //return varpath; }
private void parseAndRefreshHighlingting() { StaDynParser parser = new StaDynParser(); parser.parseAll(); currentFile = ProjectFileAST.Instance.getAstFile(FileUtilities.Instance.getCurrentOpenDocumentFilePath()); // if (parseResult == null || parseResult.Ast == null) SourceHelper.refreshHighlighting(); }
/// <summary> /// Checks if a token its a contained in the TypeTable /// First find on the TypeTable as it /// Second find appending the "Usings" of the source file /// Third find appendid the namespaces of the source file /// </summary> /// <param name="token">IToken with correct line number and colum</param> /// <returns>True if TypeTable Contains the token</returns> public bool CheckTokenTypeOnCurrentDocument(IToken token) { //Get the currect open file name string currentDocumentFileName = FileUtilities.Instance.getCurrentOpenDocumentFilePath(); //Refresh the fileName // token.setFilename(currentDocumentFileName); // Location location = ITokenToLocation.Instance.convertToLocation(token); //Location location = new Location(Path.GetFileName(currentDocumentFileName), token.getLine(), token.getColumn()); Location location = new Location(currentDocumentFileName, token.getLine(), token.getColumn()); TypeExpression tokenType = null; //Simple search on typeTable tokenType = TypeTable.Instance.GetType(token.getText(), location); if (tokenType != null) { return(true); } //Get the current AST StaDynSourceFileAST currentSourceFile = ProjectFileAST.Instance.getAstFile(currentDocumentFileName); if (currentSourceFile == null || currentSourceFile.Ast == null) { return(false); } //if (currentSourceFile.Ast == null) return false; tokenType = this.findTypeAtUsings(token.getText(), location, currentSourceFile.Ast.Usings); if (tokenType != null) { return(true); } tokenType = this.findTypeAtCurrentNameSpace(token.getText(), location, currentSourceFile.Ast); if (tokenType != null) { return(true); } return(false); }
//public bool checkDynamicVar(IToken token) public bool checkDynamicVar(string varName, int line, int column, StaDynSourceFileAST file) { VarPath varpath = this.getVarPath(varName, line, column, file); if (varpath == null) { return(false); } DynVarManager dynVarManager = new DynVarManager(); string filename = Path.ChangeExtension(file.FileName, DynVarManagement.DynVarManager.DynVarFileExt); dynVarManager.LoadOrCreate(filename); return(dynVarManager.IsDynamic(varpath)); }
private AstNode getCurrentCast(StaDynSourceFileAST parseResult, ITextSnapshot snapshot, int start, int line, int column) { VisitorFindCast vfc = new VisitorFindCast(); //parseResult.Ast.Accept(vfc, new Location(Path.GetFileName(parseResult.FileName), line, column)); parseResult.Ast.Accept(vfc, new Location(parseResult.FileName, line, column)); Stack <AstNode> castStack = vfc.castStack; if (castStack == null || castStack.Count == 0) { return(null); } int contCloseParent = SourceHelper.countCharAppearances(snapshot, start, line - 1, 0, ')'); //SnapshotPoint externalCloseParenPosition = new SnapshotPoint(snapshot, start); //SnapshotSpan externalOpenParenPosition = new SnapshotSpan(); //SourceHelper.FindMatchingOpenChar(externalCloseParenPosition, '(', ')', 0, out externalOpenParenPosition); //SnapshotPoint firtsOpenParentPosition = new SnapshotPoint(snapshot, externalOpenParenPosition.Start); //SnapshotSpan firtsCloseParenPosition = new SnapshotSpan(); //SourceHelper.FindFirstAppearanceOf(firtsOpenParentPosition, ')', out firtsCloseParenPosition); //int columnDiference = start - firtsCloseParenPosition.Start; //AstNode foundNode = (AstNode)parseResult.Ast.Accept(new VisitorFindNode(), new Location(Path.GetFileName(parseResult.FileName), line, column - columnDiference)); //return foundNode; contCloseParent--; if (contCloseParent > castStack.Count) { return(null); } AstNode currentMethod = null; for (int i = 0; i < contCloseParent; i++) { currentMethod = castStack.Pop(); } return(currentMethod); }
private List <Completion> getCurrentClassMemebers(int line, int column) { List <Completion> currentClassMembers = new List <Completion>(); StaDynSourceFileAST file = ProjectFileAST.Instance.getAstFile(FileUtilities.Instance.getCurrentOpenDocumentFilePath()); if (file == null || file.Ast == null) { return(null); } //Location currentLocation = new Location(Path.GetFileName(file.FileName), line + 1, column); Location currentLocation = new Location(file.FileName, line + 1, column); ClassDefinition currentClass = StaDynIntellisenseHelper.Instance.getCurrentClass(currentLocation, file.Ast); if (currentClass == null) { return(currentClassMembers); } Declaration member; string name; for (int i = 0; i < currentClass.MemberCount; i++) { member = currentClass.GetMemberElement(i); name = member.FullName; if (!String.IsNullOrEmpty(name)) { name = name.Substring(name.LastIndexOf(".") + 1); ImageSource image = CompletionGlyph.Instance.getImage(member.TypeExpr, this._glyphService); currentClassMembers.Add(new Completion(name, name, member.TypeExpr.FullName, image, name)); } } //Sort the elements currentClassMembers.Sort((x, y) => string.Compare(x.DisplayText, y.DisplayText)); return(currentClassMembers); }
public AstNode getCurrentInvocation(StaDynSourceFileAST parseResult, ITextSnapshot snapshot, int start, int line, int column) { VisitorFindCallMethod vfc = new VisitorFindCallMethod(); //parseResult.Ast.Accept(vfc, new Location(Path.GetFileName(parseResult.FileName), line, column)); parseResult.Ast.Accept(vfc, new Location(parseResult.FileName, line, column)); Stack <AstNode> methodStack = vfc.methodStack; if (methodStack == null || methodStack.Count == 0) { return(null); } int contCloseParent = SourceHelper.countCharAppearances(snapshot, start, line - 1, 0, ')'); //SnapshotPoint starPoint = new SnapshotPoint(snapshot, start); //SnapshotSpan openParenPosition = new SnapshotSpan(); //SourceHelper.FindMatchingOpenChar(starPoint, '(', ')', 0, out openParenPosition); //int columnDiference = start - openParenPosition.Start; //AstNode foundNode = (AstNode)parseResult.Ast.Accept(new VisitorFindNode(), new Location(Path.GetFileName(parseResult.FileName), line, column - columnDiference)); //return foundNode; //Maybe an error or casting if (contCloseParent > methodStack.Count) { return(null); } AstNode currentMethod = null; for (int i = 0; i < contCloseParent; i++) { currentMethod = methodStack.Pop(); } return(currentMethod); }
//Other public methods #region DeclareExcplicit /// <summary> /// Modify var reference declaration changing from "var" to its actual type if possible. /// This method is public in order to be called by <see cref="CommandHandler.DeclareExplicitCommand"/> /// and <see cref="DeclareEverythingExplicitVisitor"/>. /// The operation will fail if the declaration has more than one type along its scope (counting as well /// types inside UnionType types). /// </summary> /// <param name="id">IdDeclaration node for the var reference declaration.</param> /// <param name="method">MethodDefinition node containing the var reference declaration.</param> /// <param name="buffer">IVsTextLines object containing document's content.</param> /// <param name="doc">TextDocument object for the document.</param> /// public void DeclareExplicit //public void DeclareExplicit(IdDeclaration id, MethodDefinition method, IVsTextLines buffer, TextDocument doc) //public void DeclareExplicit() //{ // int lineNumber = this.currentCaretPosition.X ; // int column = this.currentCaretPosition.Y; // var snapshot = FileUtilities.Instance.getCurrentTextSnapShot(); // int start = FileUtilities.Instance.getCurrentCaretPosition(); // StaDynVariablesInScopeTable infoVariablesInScope = StaDynIntellisenseHelper.Instance.getVariablesInCurrentScope(lineNumber +1, column, snapshot, start,true); // string varName = ((IdDeclaration)foundNode).Identifier; // var SSAVariablesList = new List<Declaration>(); // //Look for the same variable in the current scope // for (int i = 0; i < infoVariablesInScope.Table.Count; i++) // { // if (infoVariablesInScope.Table[i].Count > 0) // { // foreach (KeyValuePair<string, IdDeclaration> variable in infoVariablesInScope.Table[i]) // { // var type = variable.Value.TypeExpr; // if (variable.Key.StartsWith(varName) && type is TypeVariable && ((TypeVariable)type).Substitution !=null) // SSAVariablesList.Add(variable.Value); // } // } // } // if (SSAVariablesList.Count !=1) // { // string message; // if (SSAVariablesList.Count == 0) // message = "The var reference named '" + varName + // "' cannot be declared explicitly since it has no type yet\n"; // else // { // message = "The var reference named '" + varName + // "' cannot be declared explicitly since it has more than one type within its scope:\n"; // foreach (Declaration node in SSAVariablesList) // message += " - " + ((TypeVariable)node.TypeExpr).Substitution.FullName + "\n"; // message += "To be able to declare explicitly this reference, create a new type from which " // + "all this types will inherit"; // } // MessageBox.Show( // message, // "Cannot declare explicit", // MessageBoxButtons.OK, MessageBoxIcon.Information); // return; // } // SourceHelper.replaceWord(snapshot, lineNumber, "var", ((TypeVariable)SSAVariablesList[0].TypeExpr).Substitution.FullName); //} #endregion #region GetAllTypes /// <summary> /// Get all types a reference has or may have along the method where it is declared. /// </summary> /// <param name="identifier">Name of the identifier.</param> /// <param name="method">Method where the identifier is declared.</param> /// <returns>Set of types assigned to the identifier. Types contained in /// UnionTypes are recursively inserted in the set.</returns> //public HashSet<TypeExpression> GetAllTypes(string identifier, MethodDefinition method) //{ // //Verify that the variable has only one type along the block // //(Making use of SSA duplicated IdDeclaration nodes for that) // //SearchInfo info = new SearchInfo(-1, -1, SearchReason.VarIdDeclarationSearch, StoreMode.StoreAll); // //if (method != null) // // method.Accept(new SearchVisitor(), info); // //HashSet<TypeExpression> types = new HashSet<TypeExpression>(); // //IdDeclaration id; // //foreach (AstNode node in info.NodeList) // //{ // // id = node as IdDeclaration; // // if (id == null | !id.Identifier.Equals(identifier)) // // continue; // // TypeVariable varType = id.TypeExpr as TypeVariable; // // TypeExpression substitutionType = varType != null ? varType.Substitution : null; // // if (substitutionType == null) // // continue; // // if (substitutionType is UnionType) // // { // // types.UnionWith(getTypesFromUnion(substitutionType as UnionType)); // // continue; // // } // // types.Add(substitutionType); // //} // //return types; //} #endregion // Private methods #region searchDynVarInfo //private SearchInfo searchDynVarInfo() //{ // TokenInfo token = null; // int line; // int column; // string tokenText = TextTools.GetCurrentTokenInfo(out token, out line, out column); // StaDynLanguage lang = Package.GetGlobalService(typeof(StaDynLanguage)) as StaDynLanguage; // DTE dte = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SDTE)) as DTE; // StaDynScope scope = lang.GetParseResult(dte.ActiveDocument.FullName); // TextTools.VsToInference(ref line, ref column); // SearchInfo searchInfo = new SearchInfo(line, column, tokenText, SearchReason.AnyVarSearch, StoreMode.NamesAndNodes); // scope.Ast.Accept(new SearchVisitor(), searchInfo); // return searchInfo; //} #endregion #region beforeQueryStatusCommonTasks /// <summary> /// Performs several tasks useful for the commands' BeforeQueryStatus handlers. /// Stores in lastSearchInfo information retrieved by <see cref="CommandHandler.searchDynVarInfo"/>. /// </summary> /// <param name="isStaDynFile">Active document is a ".stadyn" file.</param> /// <param name="isVar">Token at cursor's location is a var reference.</param> /// <param name="isDynamic">Token at cursor's location is a dynamic var reference.</param> private void beforeQueryStatusCommonTasks(out bool isStaDynFile, out bool isVar, out bool isDynamic) { isStaDynFile = isVar = isDynamic = false; isStaDynFile = FileUtilities.Instance.checkCurrentFileExtension(".stadyn"); //Get the span of the current word (caret on) var currentWordTextSpan = SourceHelper.getCurrentTextSpan(); this.currentCaretPosition.X = currentWordTextSpan.iStartLine; this.currentCaretPosition.Y = currentWordTextSpan.iEndIndex; int line = currentWordTextSpan.iStartLine; int column = currentWordTextSpan.iEndIndex + 1; StaDynParser parser = new StaDynParser(); parser.parseAll(); currentFile = ProjectFileAST.Instance.getAstFile(FileUtilities.Instance.getCurrentOpenDocumentFilePath()); if (currentFile == null || currentFile.Ast == null) { return; } //string currentWord = SourceHelper.getCurrentWord(); //this.foundNode = (AstNode)currentFile.Ast.Accept(new VisitorFindNode(), new Location(Path.GetFileName(currentFile.FileName), line + 1, column)); this.foundNode = (AstNode)currentFile.Ast.Accept(new VisitorFindNode(), new Location(currentFile.FileName, line + 1, column)); if (foundNode is Declaration) { //Declaration dec = foundNode as Declaration; IdDeclaration idDec = foundNode as IdDeclaration; isVar = idDec.TypeExpr is TypeVariable; isDynamic = StaDynDynamicHelper.Instance.checkDynamicVar(idDec.Identifier, line, column, currentFile); //isDynamic = idDec.TypeExpr.IsDynamic; } }
public StaDynVariablesInScopeTable getVariablesInCurrentScope(int line, int column, ITextSnapshot snapshot, int start, bool includeSSAVars) { var variablesInScope = new StaDynVariablesInScopeTable(); StaDynSourceFileAST file = ProjectFileAST.Instance.getAstFile(FileUtilities.Instance.getCurrentOpenDocumentFilePath()); if (file == null || file.Ast == null) { return(null); } //AstNode foundNode = (AstNode)file.Ast.Accept(new VisitorFindNode(), new Location(Path.GetFileName(file.FileName), line + 1, column)); AstNode foundNode = (AstNode)file.Ast.Accept(new VisitorFindNode(), new Location(file.FileName, line + 1, column)); if (foundNode == null) { return(null); } variablesInScope = file.Ast.Accept(new VisitorFindDefinitionsInScope(includeSSAVars), foundNode) as StaDynVariablesInScopeTable; if (variablesInScope == null) { return(variablesInScope); } /* * The foundNode is the next node that we actually are looking for. * So, we must pop as many groups of variables as closing braces we found * between foundeNode location and the location where the completion was triggered. */ int blocksToPop = SourceHelper.countCharAppearances(snapshot, start, foundNode.Location.Line, foundNode.Location.Column, '}'); for (int i = 0; i < blocksToPop; i++) { variablesInScope.Reset(); } return(variablesInScope); }
private AstNode getCurrentArray(StaDynSourceFileAST parseResult, ITextSnapshot snapshot, int start, int line, int column) { VisitorFindArray vfa = new VisitorFindArray(); //parseResult.Ast.Accept(vfa, new Location(Path.GetFileName(parseResult.FileName), line, column)); parseResult.Ast.Accept(vfa, new Location(parseResult.FileName, line, column)); Stack <AstNode> arrayStack = vfa.arrayStack; if (arrayStack == null) { return(null); } int contCloseBracket = SourceHelper.countCharAppearances(snapshot, start, line - 1, 0, ']'); AstNode currentArray = null; for (int i = 0; i < contCloseBracket; i++) { currentArray = arrayStack.Pop(); } return(currentArray); }
public void AugmentQuickInfoSession(IQuickInfoSession session, IList <object> quickInfoContent, out ITrackingSpan applicableToSpan) { applicableToSpan = null; if (_disposed) { throw new ObjectDisposedException("StaDynQuickInfoSource"); } var triggerPoint = (SnapshotPoint)session.GetTriggerPoint(_buffer.CurrentSnapshot); char c = triggerPoint.GetChar(); if (triggerPoint == null || Char.IsWhiteSpace(c)) { return; } //StaDynParser parser = new StaDynParser(session.TextView.TextBuffer, FileUtilities.Instance.getCurrentOpenDocumentFilePath()); ////Parse source //StaDynSourceFileAST parseResult = parser.parseSource(); ////parseResult = DecorateAST.Instance.completeDecorateAST(parseResult); ////parseResult= DecorateAST.Instance.completeDecorateAndUpdate(parseResult.FileName, true); //parseResult = DecorateAST.Instance.completeDecorateAndUpdate(parseResult); StaDynParser parser = new StaDynParser(); parser.parseAll(); StaDynSourceFileAST parseResult = ProjectFileAST.Instance.getAstFile(FileUtilities.Instance.getCurrentOpenDocumentFilePath()); if (parseResult == null || parseResult.Ast == null) { return; } foreach (IMappingTagSpan <StaDynTokenTag> curTag in _aggregator.GetTags(new SnapshotSpan(triggerPoint, triggerPoint))) { var tagType = curTag.Tag.type; var tagSpan = curTag.Span.GetSpans(_buffer).First(); applicableToSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(tagSpan, SpanTrackingMode.EdgeExclusive); string output = String.Empty; switch (tagType) { case StaDynTokenTypes.Text: case StaDynTokenTypes.Identifier: case StaDynTokenTypes.String: case StaDynTokenTypes.TypeDefinition: case StaDynTokenTypes.DynamicVar: case StaDynTokenTypes.Literal: //Gets the tag info output = this.getQuickInfo(curTag, parseResult); break; case StaDynTokenTypes.Operator: case StaDynTokenTypes.Delimiter: case StaDynTokenTypes.WhiteSpace: //Nothing to do continue; case StaDynTokenTypes.Keyword: case StaDynTokenTypes.LineComment: case StaDynTokenTypes.Comment: case StaDynTokenTypes.Number: if (curTag.Tag.StaDynToken.getText() == ".") { continue; } //Show the same tag output = curTag.Tag.StaDynToken.getText(); break; default: break; } quickInfoContent.Add(output); } }
public void AugmentSignatureHelpSession(ISignatureHelpSession session, IList <ISignature> signatures) { ITextSnapshot snapshot = m_textBuffer.CurrentSnapshot; int position = session.GetTriggerPoint(m_textBuffer).GetPosition(snapshot); ITrackingSpan applicableToSpan = m_textBuffer.CurrentSnapshot.CreateTrackingSpan( new Span(position, 0), SpanTrackingMode.EdgeInclusive, 0); //First try to get a compilable source code snapshot = snapshot.TextBuffer.Insert(position, "();"); Span spanToRemove = new Span(position, 3); //StaDynParser parser = new StaDynParser(snapshot.TextBuffer, FileUtilities.Instance.getCurrentOpenDocumentFilePath()); ////Parse source //StaDynSourceFileAST parseResult = parser.parseSource(); //parseResult = DecorateAST.Instance.completeDecorateAndUpdate(parseResult); StaDynParser parser = new StaDynParser(); parser.parseAll(); StaDynSourceFileAST parseResult = ProjectFileAST.Instance.getAstFile(FileUtilities.Instance.getCurrentOpenDocumentFilePath()); if (parseResult == null || parseResult.Ast == null) { snapshot = snapshot.TextBuffer.Delete(spanToRemove); return; } System.Drawing.Point caretPosition = FileUtilities.Instance.getCurrentCaretPoint(); int column = caretPosition.Y; int line = caretPosition.X + 1; //AstNode foundNode = (AstNode)parseResult.Ast.Accept(new VisitorFindNode(), new Location(Path.GetFileName(parseResult.FileName), line, column)); AstNode foundNode = (AstNode)parseResult.Ast.Accept(new VisitorFindNode(), new Location(parseResult.FileName, line, column)); //Signature help is not needed on method definition if (foundNode is MethodDefinition) { snapshot = snapshot.TextBuffer.Delete(spanToRemove); return; } AstNode lastInvocationNode = StaDynIntellisenseHelper.Instance.getCurrentInvocation(parseResult, snapshot, position, line, column); //StaDynSourceFileAST file = ProjectFileAST.Instance.getAstFile(FileUtilities.Instance.getCurrentOpenDocumentFilePath()); //if (file.Ast == null) return ; //AstNode foundNode = (AstNode)file.Ast.Accept(new VisitorFindNode(), new Location(Path.GetFileName(file.FileName), line, column)); //Remove added chars snapshot = snapshot.TextBuffer.Delete(spanToRemove); if (lastInvocationNode == null) { return; } this.createSignatures(lastInvocationNode, m_textBuffer, applicableToSpan, signatures); /*****************************************/ //signatures.Add(CreateSignature(m_textBuffer, "add(int firstInt, int secondInt)", "Documentation for adding integers.", applicableToSpan)); //signatures.Add(CreateSignature(m_textBuffer, "add(double firstDouble, double secondDouble)", "Documentation for adding doubles.", applicableToSpan)); }