1 | // |
---|
2 | // Lol Engine - VsLol add-in for Visual Studio |
---|
3 | // |
---|
4 | // Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net> |
---|
5 | // This program is free software; you can redistribute it and/or |
---|
6 | // modify it under the terms of the Do What The Fuck You Want To |
---|
7 | // Public License, Version 2, as published by Sam Hocevar. See |
---|
8 | // http://www.wtfpl.net/ for more details. |
---|
9 | // |
---|
10 | |
---|
11 | using System; |
---|
12 | using System.Collections.Generic; |
---|
13 | using System.Linq; |
---|
14 | using System.Text; |
---|
15 | |
---|
16 | using Microsoft.VisualStudio; |
---|
17 | using Microsoft.VisualStudio.Package; |
---|
18 | using Microsoft.VisualStudio.TextManager.Interop; |
---|
19 | using Microsoft.VisualStudio.OLE.Interop; |
---|
20 | |
---|
21 | namespace lol |
---|
22 | { |
---|
23 | |
---|
24 | class LolFxLanguageService : LanguageService |
---|
25 | { |
---|
26 | public override string GetFormatFilterList() |
---|
27 | { |
---|
28 | throw new NotImplementedException(); |
---|
29 | } |
---|
30 | |
---|
31 | public override LanguagePreferences GetLanguagePreferences() |
---|
32 | { |
---|
33 | if (m_preferences == null) |
---|
34 | { |
---|
35 | m_preferences = new LanguagePreferences(this.Site, |
---|
36 | typeof(LolFxLanguageService).GUID, this.Name); |
---|
37 | m_preferences.Init(); |
---|
38 | } |
---|
39 | return m_preferences; |
---|
40 | } |
---|
41 | |
---|
42 | public override IScanner GetScanner(IVsTextLines buffer) |
---|
43 | { |
---|
44 | if (m_scanner == null) |
---|
45 | { |
---|
46 | m_scanner = new LolFxScanner(buffer); |
---|
47 | } |
---|
48 | return m_scanner; |
---|
49 | } |
---|
50 | |
---|
51 | public override string Name |
---|
52 | { |
---|
53 | get { return "LolFx"; } |
---|
54 | } |
---|
55 | |
---|
56 | public override AuthoringScope ParseSource(ParseRequest req) |
---|
57 | { |
---|
58 | return new LolFxAuthoringScope(); |
---|
59 | } |
---|
60 | |
---|
61 | private LanguagePreferences m_preferences; |
---|
62 | private LolFxScanner m_scanner; |
---|
63 | |
---|
64 | internal class LolFxScanner : IScanner |
---|
65 | { |
---|
66 | public LolFxScanner(IVsTextBuffer buffer) |
---|
67 | { |
---|
68 | m_buffer = buffer; |
---|
69 | } |
---|
70 | |
---|
71 | bool IScanner.ScanTokenAndProvideInfoAboutIt(TokenInfo tokeninfo, ref int state) |
---|
72 | { |
---|
73 | while (m_offset < m_source.Length) |
---|
74 | { |
---|
75 | if (m_source[m_offset] == ' ' || m_source[m_offset] == '\t') |
---|
76 | { |
---|
77 | ++m_offset; |
---|
78 | continue; |
---|
79 | } |
---|
80 | |
---|
81 | tokeninfo.StartIndex = m_offset; |
---|
82 | tokeninfo.EndIndex = m_offset; |
---|
83 | tokeninfo.Type = TokenType.Unknown; |
---|
84 | switch (state % 4) |
---|
85 | { |
---|
86 | case 0: tokeninfo.Color = TokenColor.Number; break; |
---|
87 | case 1: tokeninfo.Color = TokenColor.Text; break; |
---|
88 | case 2: tokeninfo.Color = TokenColor.Keyword; break; |
---|
89 | case 3: tokeninfo.Color = TokenColor.Comment; break; |
---|
90 | } |
---|
91 | ++m_offset; |
---|
92 | ++state; |
---|
93 | return true; |
---|
94 | } |
---|
95 | |
---|
96 | return false; |
---|
97 | } |
---|
98 | |
---|
99 | enum State |
---|
100 | { |
---|
101 | Default, |
---|
102 | CComment, |
---|
103 | CppComment, |
---|
104 | String, |
---|
105 | } |
---|
106 | |
---|
107 | void IScanner.SetSource(string source, int offset) |
---|
108 | { |
---|
109 | m_source = source; |
---|
110 | m_offset = offset; |
---|
111 | } |
---|
112 | |
---|
113 | private IVsTextBuffer m_buffer; |
---|
114 | string m_source; |
---|
115 | int m_offset; |
---|
116 | } |
---|
117 | |
---|
118 | internal class LolFxAuthoringScope : AuthoringScope |
---|
119 | { |
---|
120 | public override string GetDataTipText(int line, int col, out TextSpan span) |
---|
121 | { |
---|
122 | span = new TextSpan(); |
---|
123 | return null; |
---|
124 | } |
---|
125 | |
---|
126 | public override Declarations GetDeclarations(IVsTextView view, |
---|
127 | int line, |
---|
128 | int col, |
---|
129 | TokenInfo info, |
---|
130 | ParseReason reason) |
---|
131 | { |
---|
132 | return null; |
---|
133 | } |
---|
134 | |
---|
135 | public override string Goto(VSConstants.VSStd97CmdID cmd, IVsTextView textView, int line, int col, out TextSpan span) |
---|
136 | { |
---|
137 | span = new TextSpan(); |
---|
138 | return null; |
---|
139 | } |
---|
140 | |
---|
141 | public override Methods GetMethods(int line, int col, string name) |
---|
142 | { |
---|
143 | return null; |
---|
144 | } |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | } /* namespace lol */ |
---|