1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using ICSharpCode.NRefactory.CSharp;
|
---|
23 | using ICSharpCode.NRefactory.CSharp.Completion;
|
---|
24 | using ICSharpCode.NRefactory.CSharp.Resolver;
|
---|
25 | using ICSharpCode.NRefactory.CSharp.TypeSystem;
|
---|
26 | using ICSharpCode.NRefactory.Editor;
|
---|
27 | using ICSharpCode.NRefactory.TypeSystem;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.CodeEditor {
|
---|
30 | internal class CSharpCodeCompletionContext {
|
---|
31 | public readonly IDocument Document;
|
---|
32 | public readonly int Offset;
|
---|
33 | public readonly IProjectContent ProjectContent;
|
---|
34 | public readonly ICompilation Compilation;
|
---|
35 | public readonly CSharpResolver Resolver;
|
---|
36 | public readonly CSharpTypeResolveContext TypeResolveContextAtCaret;
|
---|
37 | public readonly ICompletionContextProvider CompletionContextProvider;
|
---|
38 |
|
---|
39 | public CSharpCodeCompletionContext(IDocument document, int offset, IProjectContent projectContent) {
|
---|
40 | Document = new ReadOnlyDocument(document, document.FileName);
|
---|
41 | Offset = offset;
|
---|
42 |
|
---|
43 | var parser = new CSharpParser();
|
---|
44 | var syntaxTree = parser.Parse(document, document.FileName);
|
---|
45 | syntaxTree.Freeze();
|
---|
46 | var unresolvedFile = syntaxTree.ToTypeSystem();
|
---|
47 |
|
---|
48 | ProjectContent = projectContent.AddOrUpdateFiles(unresolvedFile);
|
---|
49 | Compilation = projectContent.CreateCompilation();
|
---|
50 |
|
---|
51 | var location = document.GetLocation(offset);
|
---|
52 | Resolver = unresolvedFile.GetResolver(Compilation, location);
|
---|
53 | TypeResolveContextAtCaret = unresolvedFile.GetTypeResolveContext(Compilation, location);
|
---|
54 | CompletionContextProvider = new DefaultCompletionContextProvider(document, unresolvedFile);
|
---|
55 | }
|
---|
56 | }
|
---|
57 | }
|
---|