当前位置: 首页>>代码示例>>C#>>正文


C# ReadOnlyDocument.GetOffset方法代码示例

本文整理汇总了C#中ICSharpCode.NRefactory.Editor.ReadOnlyDocument.GetOffset方法的典型用法代码示例。如果您正苦于以下问题:C# ReadOnlyDocument.GetOffset方法的具体用法?C# ReadOnlyDocument.GetOffset怎么用?C# ReadOnlyDocument.GetOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICSharpCode.NRefactory.Editor.ReadOnlyDocument的用法示例。


在下文中一共展示了ReadOnlyDocument.GetOffset方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CollectMembers

		void CollectMembers(string code, string memberName, bool includeOverloads = true)
		{
			StringBuilder sb = new StringBuilder();
			List<int> offsets = new List<int>();
			foreach (var ch in code) {
				if (ch == '$') {
					offsets.Add(sb.Length);
					continue;
				}
				sb.Append(ch);
			}
			var syntaxTree = SyntaxTree.Parse(sb.ToString (), "test.cs");
			var unresolvedFile = syntaxTree.ToTypeSystem();
			var compilation = TypeSystemHelper.CreateCompilation(unresolvedFile);

			var symbol = FindReferencesTest.GetSymbol(compilation, memberName);
			var col = new SymbolCollector();
			col.IncludeOverloads = includeOverloads;
			col.GroupForRenaming = true;

			var result = col.GetRelatedSymbols (new Lazy<TypeGraph>(() => new TypeGraph (compilation.Assemblies)),
			                                   symbol);
			if (offsets.Count != result.Count()) {
				foreach (var a in result)
					Console.WriteLine(a);
			}
			Assert.AreEqual(offsets.Count, result.Count());
			var doc = new ReadOnlyDocument(sb.ToString ());
			result
				.Select(r => doc.GetOffset ((r as IEntity).Region.Begin))
				.SequenceEqual(offsets);
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:32,代码来源:SymbolCollectorTests.cs

示例2: CreateProvider

        public IEnumerable<ICompletionData> CreateProvider(AutoCompleteRequest request)
        {
            var editorText = request.Buffer ?? "";
            var filename = request.FileName;
            var partialWord = request.WordToComplete ?? "";

            var doc = new ReadOnlyDocument(editorText);
            var loc = new TextLocation(request.Line, request.Column - partialWord.Length);
            int cursorPosition = doc.GetOffset(loc);
            //Ensure cursorPosition only equals 0 when editorText is empty, so line 1,column 1
            //completion will work correctly.
            cursorPosition = Math.Max(cursorPosition, 1);
            cursorPosition = Math.Min(cursorPosition, editorText.Length);

            var res = _parser.ParsedContent(editorText, filename);
            var rctx = res.UnresolvedFile.GetTypeResolveContext(res.Compilation, loc);

            ICompletionContextProvider contextProvider = new DefaultCompletionContextProvider(doc, res.UnresolvedFile);
            var engine = new CSharpCompletionEngine(doc, contextProvider, new CompletionDataFactory(partialWord), res.ProjectContent, rctx)
                {
                    EolMarker = Environment.NewLine
                };

            _logger.Debug("Getting Completion Data");

            IEnumerable<ICompletionData> data = engine.GetCompletionData(cursorPosition, true);
            _logger.Debug("Got Completion Data");

            return data.Where(d => d != null && d.DisplayText.IsValidCompletionFor(partialWord))
                       .FlattenOverloads()
                       .RemoveDupes()
                       .OrderBy(d => d.DisplayText);
        }
开发者ID:CSRedRat,项目名称:Omnisharp,代码行数:33,代码来源:AutoCompleteHandler.cs

示例3: EmptyReadOnlyDocument

		public void EmptyReadOnlyDocument()
		{
			IDocument document = new ReadOnlyDocument(string.Empty);
			Assert.AreEqual(string.Empty, document.Text);
			Assert.AreEqual(0, document.TextLength);
			Assert.AreEqual(1, document.LineCount);
			Assert.AreEqual(0, document.GetOffset(1, 1));
			Assert.AreEqual(new TextLocation(1, 1), document.GetLocation(0));
			
			Assert.AreEqual(0, document.GetLineByNumber(1).Offset);
			Assert.AreEqual(0, document.GetLineByNumber(1).EndOffset);
			Assert.AreEqual(0, document.GetLineByNumber(1).Length);
			Assert.AreEqual(0, document.GetLineByNumber(1).TotalLength);
			Assert.AreEqual(0, document.GetLineByNumber(1).DelimiterLength);
			Assert.AreEqual(1, document.GetLineByNumber(1).LineNumber);
		}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:16,代码来源:ReadOnlyDocumentTests.cs

示例4: CreateProvider

		static CompletionDataList CreateProvider (string text, CompilationUnit compilationUnit, CSharpCompletionEngine engine, ReadOnlyDocument doc, TextLocation loc)
		{
			var cursorPosition = doc.GetOffset (loc);
			
			var data = engine.GetCompletionData (cursorPosition, true);
			
			return new CompletionDataList () {
				Data = data,
				AutoCompleteEmptyMatch = engine.AutoCompleteEmptyMatch,
				AutoSelect = engine.AutoSelect,
				DefaultCompletionString = engine.DefaultCompletionString
			};
		}
开发者ID:cohenw,项目名称:NRefactory,代码行数:13,代码来源:CodeCompletionBugTests.cs

示例5: RunFullProjectAnalysis

        public static ProjectAnalysisResult RunFullProjectAnalysis(ProjectAnalysisRequest projectAnalysisRequest) // ProjectModel projectModel, int fileId, int line, int column)
        {
            Stopwatch sw = Stopwatch.StartNew();

            ProjectAnalysisResult projectAnalysisResult = new ProjectAnalysisResult();
            ProjectModel projectModel = projectAnalysisRequest.ProjectModel;


            // Set up the project (if not already done)
            if (projectModel.ProjectContent == null)
            {
                projectModel.ProjectContent = new CSharpProjectContent();
                projectModel.ProjectContent = projectModel.ProjectContent.AddAssemblyReferences(QCReferences.Value);
            }

            // For each new file, we need to integrate it into the project content
            var fileModelsInProject = projectModel.GetFileDescendants().ToArray();
            foreach (var fileModelInProject in fileModelsInProject)
            {
                IntegrateFileModel(projectModel, fileModelInProject);
            }

            // We can return now if no code completion was requested
            if (projectAnalysisRequest.CodeCompletionParameters == null)
            {
                projectAnalysisResult.TimeElapsed = sw.Elapsed;
                return projectAnalysisResult;
            }

            // Now it's time to give attention specifically to the matter of resolving the code completion
            // options.  This, of course, requires a deeper analysis of the specified file...
            
            var codeCompletionParams = projectAnalysisRequest.CodeCompletionParameters;

            // Locate the file in the project
            ProjectFileModel fileModel = projectModel.FindFile(codeCompletionParams.FileId);
            if (fileModel == null)
                throw new Exception("Specified file does not exist in this project");
            

            // Create a TypeSystem.ICompilation that allows resolving within the project.
            var compilation = projectModel.ProjectContent.CreateCompilation();

            #region Resolve text cursor/caret location
            
            // The text cursor position is crucial to creating a properly-scoped type resolution context
            // so as to get relevant code completion suggestions.
            int textCursorOffset;
            TextLocation textCursorLocation;
            ReadOnlyDocument doc = new ReadOnlyDocument(fileModel.Content);
            if (codeCompletionParams.Line == 0 && codeCompletionParams.Column == 0)
            {
                textCursorOffset = codeCompletionParams.Offset;
                textCursorLocation = doc.GetLocation(textCursorOffset);
                codeCompletionParams.Line = textCursorLocation.Line;
                codeCompletionParams.Column = textCursorLocation.Column;
            }
            else
            {
                textCursorLocation = new TextLocation(codeCompletionParams.Line, codeCompletionParams.Column);
                textCursorOffset = doc.GetOffset(textCursorLocation);
                codeCompletionParams.Offset = textCursorOffset;
            }

            #endregion

            #region Create and Refine the type resolution context as much as possible based upon the cursor position

            var typeResolveContext = new CSharpTypeResolveContext(compilation.MainAssembly);
            // Constrain the resolve context by using scope
            typeResolveContext = typeResolveContext
                .WithUsingScope(fileModel.UnresolvedFile.GetUsingScope(textCursorLocation)
                .Resolve(compilation));

            var curDef = fileModel.UnresolvedFile.GetInnermostTypeDefinition(textCursorLocation);
            if (curDef != null)
            {
                var resolvedDef = curDef.Resolve(typeResolveContext).GetDefinition();
                typeResolveContext = typeResolveContext.WithCurrentTypeDefinition(resolvedDef);
                var curMember = resolvedDef.Members.FirstOrDefault(m => m.Region.Begin <= textCursorLocation && textCursorLocation < m.BodyRegion.End);
                if (curMember != null)
                {
                    typeResolveContext = typeResolveContext.WithCurrentMember(curMember);
                }
            }

            #endregion

            // The purpose of the rest of these steps is a little fuzzy in my mind...  
            // I'm still trying to understand them fully and if/why they're all needed.
            // It seems there is some redundancy here...

            var completionContext = new DefaultCompletionContextProvider(doc, fileModel.UnresolvedFile);

            #region Add Preprocessor Symbols??
            completionContext.AddSymbol("TEST");
            foreach (var sym in fileModel.SyntaxTree.ConditionalSymbols)
                completionContext.AddSymbol(sym);
            #endregion

//.........这里部分代码省略.........
开发者ID:uluhonolulu,项目名称:QCCodingServices.NET,代码行数:101,代码来源:NRefactoryUtils.cs

示例6: TestRename

        void TestRename(string code, string symbolName)
        {
            StringBuilder sb = new StringBuilder();
            List<int> offsets = new List<int>();
            foreach (var ch in code) {
                if (ch == '$') {
                    offsets.Add(sb.Length);
                    continue;
                }
                sb.Append(ch);
            }
            Init(sb.ToString ());
            findReferences.WholeVirtualSlot = true;
            var doc = new ReadOnlyDocument(sb.ToString ());
            var result = Rename(symbolName, "x", false);
            Assert.AreEqual(offsets.Count, result.Count);

            result.Select(r => doc.GetOffset (r.StartLocation)).SequenceEqual(offsets);
        }
开发者ID:dyxu,项目名称:vimrc,代码行数:19,代码来源:FindReferencesTest.cs

示例7: InsertEventHandlerInternal

		void InsertEventHandlerInternal(string methodName, IEvent evt)
		{
			CSharpCodeGenerator generator = new CSharpCodeGenerator();
			var primary = loader.GetPrimaryTypeDefinition();
			var evtHandler = primary.GetMethods(m => m.Name == methodName, GetMemberOptions.IgnoreInheritedMembers).FirstOrDefault();
			if (evtHandler == null) {
				generator.InsertEventHandler(primary, methodName, evt, true);
			} else {
				CSharpBinding.Parser.CSharpFullParseInformation parseInfo;
				var node = evtHandler.GetDeclaration(out parseInfo) as MethodDeclaration;
				var fileName = new FileName(evtHandler.Region.FileName);
				var fileContentFinder = new ParseableFileContentFinder();
				
				if (node != null && !node.Body.IsNull) {
					var location = node.Body.FirstChild.StartLocation;
					var firstStatement = node.Body.Children.OfType<Statement>().FirstOrDefault();
					
					if (firstStatement == null) {
						var fileContent = fileContentFinder.Create(fileName);
						var document = new ReadOnlyDocument(fileContent);
						var offset = document.GetOffset(new TextLocation(location.Line + 1, 1));
						var length = DocumentUtilities.GetWhitespaceAfter(fileContent, offset).Length;
						location = new TextLocation(location.Line + 1, length + 1);
					} else {
						location = firstStatement.StartLocation;
					}
					SD.FileService.JumpToFilePosition(fileName, location.Line, location.Column);
				}
			}
		}
开发者ID:linquize,项目名称:SharpDevelop,代码行数:30,代码来源:CSharpEventBindingService.cs


注:本文中的ICSharpCode.NRefactory.Editor.ReadOnlyDocument.GetOffset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。