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.

138 lines
4.0 KiB

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