Beispiel #1
0
 public FilePreviewItem(PreviewChangesEngine engine, string file)
 {
     Filename = file;
     _engine = engine;
     do {
         _tempFileName = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()) + ".py";
     } while (File.Exists(_tempFileName));
 }
Beispiel #2
0
 public BufferUpdater(ITextBuffer buffer, PreviewChangesEngine engine)
 {
     _buffer = buffer;
     _engine = engine;
 }
Beispiel #3
0
        public void RenameVariable(IRenameVariableInput input, IVsPreviewChangesService previewChanges)
        {
            if (IsModuleName(input)) {
                input.CannotRename("Cannot rename a module name");
                return;
            }

            var analysis = _view.GetExpressionAnalysis();

            string originalName = null;
            string privatePrefix = null;
            Expression expr = null;
            if (analysis != ExpressionAnalysis.Empty) {
                JAst ast = analysis.GetEvaluatedAst();

                expr = Statement.GetExpression(ast.Body);

                NameExpression ne = expr as NameExpression;
                MemberExpression me;
                if (ne != null) {
                    originalName = ne.Name;
                } else if ((me = expr as MemberExpression) != null) {
                    originalName = me.Name;
                }

                if (ast.PrivatePrefix != null && originalName.StartsWith("_" + ast.PrivatePrefix)) {
                    originalName = originalName.Substring(ast.PrivatePrefix.Length + 1);
                    privatePrefix = ast.PrivatePrefix;
                }

                if (originalName != null && _view.Selection.IsActive && !_view.Selection.IsEmpty) {
                    if (_view.Selection.Start.Position < analysis.Span.GetStartPoint(_view.TextBuffer.CurrentSnapshot) ||
                        _view.Selection.End.Position > analysis.Span.GetEndPoint(_view.TextBuffer.CurrentSnapshot)) {
                        originalName = null;
                    }
                }
            }

            if (originalName == null) {
                input.CannotRename("Please select a symbol to be renamed.");
                return;
            }

            bool hasVariables = false;
            foreach (var variable in analysis.Variables) {
                if (variable.Type == VariableType.Definition || variable.Type == VariableType.Reference) {
                    hasVariables = true;
                    break;
                }
            }

            IEnumerable<IAnalysisVariable> variables;
            if (!hasVariables) {
                List<IAnalysisVariable> paramVars = GetKeywordParameters(expr, originalName);

                if (paramVars.Count == 0) {
                    input.CannotRename(string.Format("No information is available for the variable '{0}'.", originalName));
                    return;
                }

                variables = paramVars;
            } else {
                variables = analysis.Variables;

            }

            var info = input.GetRenameInfo(originalName);
            if (info != null) {
                var engine = new PreviewChangesEngine(input, analysis, info, originalName, privatePrefix, _view.GetAnalyzer(), variables);
                if (info.Preview) {
                    previewChanges.PreviewChanges(engine);
                } else {
                    ErrorHandler.ThrowOnFailure(engine.ApplyChanges());
                }
            }
        }