You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

149 regels
4.0 KiB

  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. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Text;
  14. using Microsoft.VisualStudio;
  15. using Microsoft.VisualStudio.Package;
  16. using Microsoft.VisualStudio.TextManager.Interop;
  17. using Microsoft.VisualStudio.OLE.Interop;
  18. namespace lol
  19. {
  20. class LolFxLanguageService : LanguageService
  21. {
  22. public override string GetFormatFilterList()
  23. {
  24. throw new NotImplementedException();
  25. }
  26. public override LanguagePreferences GetLanguagePreferences()
  27. {
  28. if (m_preferences == null)
  29. {
  30. m_preferences = new LanguagePreferences(this.Site,
  31. typeof(LolFxLanguageService).GUID, this.Name);
  32. m_preferences.Init();
  33. }
  34. return m_preferences;
  35. }
  36. public override IScanner GetScanner(IVsTextLines buffer)
  37. {
  38. if (m_scanner == null)
  39. {
  40. m_scanner = new LolFxScanner(buffer);
  41. }
  42. return m_scanner;
  43. }
  44. public override string Name
  45. {
  46. get { return "LolFx"; }
  47. }
  48. public override AuthoringScope ParseSource(ParseRequest req)
  49. {
  50. return new LolFxAuthoringScope();
  51. }
  52. private LanguagePreferences m_preferences;
  53. private LolFxScanner m_scanner;
  54. internal class LolFxScanner : IScanner
  55. {
  56. public LolFxScanner(IVsTextBuffer buffer)
  57. {
  58. m_buffer = buffer;
  59. }
  60. bool IScanner.ScanTokenAndProvideInfoAboutIt(TokenInfo tokeninfo, ref int state)
  61. {
  62. while (m_offset < m_source.Length)
  63. {
  64. if (m_source[m_offset] == ' ' || m_source[m_offset] == '\t')
  65. {
  66. ++m_offset;
  67. continue;
  68. }
  69. tokeninfo.StartIndex = m_offset;
  70. tokeninfo.EndIndex = m_offset;
  71. tokeninfo.Type = TokenType.Unknown;
  72. switch (state % 4)
  73. {
  74. case 0: tokeninfo.Color = TokenColor.Number; break;
  75. case 1: tokeninfo.Color = TokenColor.Text; break;
  76. case 2: tokeninfo.Color = TokenColor.Keyword; break;
  77. case 3: tokeninfo.Color = TokenColor.Comment; break;
  78. }
  79. ++m_offset;
  80. ++state;
  81. return true;
  82. }
  83. return false;
  84. }
  85. enum State
  86. {
  87. Default,
  88. CComment,
  89. CppComment,
  90. String,
  91. }
  92. void IScanner.SetSource(string source, int offset)
  93. {
  94. m_source = source;
  95. m_offset = offset;
  96. }
  97. private IVsTextBuffer m_buffer;
  98. string m_source;
  99. int m_offset;
  100. }
  101. internal class LolFxAuthoringScope : AuthoringScope
  102. {
  103. public override string GetDataTipText(int line, int col, out TextSpan span)
  104. {
  105. span = new TextSpan();
  106. return null;
  107. }
  108. public override Declarations GetDeclarations(IVsTextView view,
  109. int line,
  110. int col,
  111. TokenInfo info,
  112. ParseReason reason)
  113. {
  114. return null;
  115. }
  116. public override string Goto(VSConstants.VSStd97CmdID cmd, IVsTextView textView, int line, int col, out TextSpan span)
  117. {
  118. span = new TextSpan();
  119. return null;
  120. }
  121. public override Methods GetMethods(int line, int col, string name)
  122. {
  123. return null;
  124. }
  125. }
  126. }
  127. } /* namespace lol */