private static CMakeItemDeclarations CreateCMakeHostSystemInformationDeclarations(
     CMakeCommandId id, ParseRequest req, Source source,
     List<string> priorParameters)
 {
     if (priorParameters.Count != 3 || priorParameters[2] != "QUERY")
     {
         return null;
     }
     CMakeItemDeclarations decls = new CMakeItemDeclarations();
     decls.AddItems(_cmakeHostSystemInformationKeys,
         CMakeItemDeclarations.ItemType.Command);
     return decls;
 }
 private static CMakeItemDeclarations CreateSetPropertyDeclarations(
     CMakeCommandId id, ParseRequest req, Source source,
     List<string> priorParameters)
 {
     CMakeItemDeclarations decls = null;
     int propertyIndex = priorParameters.IndexOf("PROPERTY");
     if (propertyIndex < 0)
     {
         CMakePropertyType type = CMakeProperties.GetPropertyTypeFromKeyword(
             priorParameters[0]);
         if (_propObjMethods.ContainsKey(type) &&
             !priorParameters.Any(x => _setPropertyKeywords.Contains(x)))
         {
             decls = _propObjMethods[type](id, req, source, priorParameters);
         }
         else
         {
             decls = new CMakeItemDeclarations();
         }
         if (priorParameters.Count > 1 || type == CMakePropertyType.Global)
         {
             decls.AddItems(_setPropertyKeywords,
                 CMakeItemDeclarations.ItemType.Command);
         }
         decls.ExcludeItems(priorParameters.Skip(1));
     }
     else if (propertyIndex == priorParameters.Count - 1)
     {
         CMakePropertyType type = CMakeProperties.GetPropertyTypeFromKeyword(
             priorParameters[0]);
         IEnumerable<string> properties = CMakeProperties.GetPropertiesOfType(
             type);
         decls = new CMakeItemDeclarations();
         decls.AddItems(properties, CMakeItemDeclarations.ItemType.Property);
     }
     return decls;
 }
 private static CMakeItemDeclarations CreateGetFileNameComponentDeclarations(
     CMakeCommandId id, ParseRequest req, Source source,
     List<string> priorParameters)
 {
     if (priorParameters.Count != 2)
     {
         return null;
     }
     CMakeItemDeclarations decls = new CMakeItemDeclarations();
     decls.AddItems(_getFileNameComponentComponents,
         CMakeItemDeclarations.ItemType.Command);
     return decls;
 }
 private static CMakeItemDeclarations CreateSetXPropertyDeclarations(
     CMakeCommandId id, ParseRequest req, Source source, 
     List<string> priorParameters)
 {
     bool afterPropsKeyword = false;
     if (priorParameters != null)
     {
         int index = priorParameters.FindIndex(x => x.Equals("PROPERTIES"));
         if (index >= 0)
         {
             afterPropsKeyword = true;
             if ((priorParameters.Count - index) % 2 == 1)
             {
                 IEnumerable<string> properties =
                     CMakeProperties.GetPropertiesForCommand(id);
                 if (properties != null)
                 {
                     CMakeItemDeclarations decls = new CMakeItemDeclarations();
                     decls.AddItems(properties,
                         CMakeItemDeclarations.ItemType.Property);
                     return decls;
                 }
             }
         }
     }
     if (!afterPropsKeyword)
     {
         CMakeItemDeclarations decls;
         CMakePropertyType type = CMakeProperties.GetPropertyTypeFromCommand(id);
         if (_propObjMethods.ContainsKey(type))
         {
             decls = _propObjMethods[type](id, req, source, priorParameters);
         }
         else
         {
             decls = new CMakeItemDeclarations();
         }
         if ((priorParameters != null && priorParameters.Count > 0) ||
             id == CMakeCommandId.SetSourceFilesProperties ||
             id == CMakeCommandId.SetDirectoryProperties)
         {
             // The PROPERTIES can appear in the SET_SOURCE_FILES_PROPERTIES and
             // SET_DIRECTORY_PROPERTIES command without another parameter before
             // it.
             decls.AddItem("PROPERTIES", CMakeItemDeclarations.ItemType.Command);
         }
         return decls;
     }
     return null;
 }
 private static CMakeItemDeclarations CreateGetPropertyDeclarations(
     CMakeCommandId id, ParseRequest req, Source source,
     List<string> priorParameters)
 {
     CMakeItemDeclarations decls = null;
     if (priorParameters != null)
     {
         if (priorParameters.Count == 1)
         {
             decls = new CMakeItemDeclarations();
             decls.AddItems(CMakeProperties.GetPropertyTypeKeywords(),
                 CMakeItemDeclarations.ItemType.Command);
         }
         else if (priorParameters.Count > 2 &&
             priorParameters[priorParameters.Count - 1] == "PROPERTY")
         {
             IEnumerable<string> properties = CMakeProperties.GetPropertiesOfType(
                 CMakeProperties.GetPropertyTypeFromKeyword(
                 priorParameters[1]));
             decls = new CMakeItemDeclarations();
             decls.AddItems(properties, CMakeItemDeclarations.ItemType.Property);
         }
         else if (priorParameters.Count == 2)
         {
             CMakePropertyType type = CMakeProperties.GetPropertyTypeFromKeyword(
                 priorParameters[1]);
             if (_propObjMethods.ContainsKey(type))
             {
                 decls = _propObjMethods[type](id, req, source, priorParameters);
             }
             else
             {
                 decls = new CMakeItemDeclarations();
             }
             if (!CMakeProperties.IsObjectRequired(type))
             {
                 decls.AddItem("PROPERTY",
                     CMakeItemDeclarations.ItemType.Command);
             }
         }
         else if (priorParameters.Count == 3)
         {
             decls = new CMakeItemDeclarations();
             decls.AddItem("PROPERTY", CMakeItemDeclarations.ItemType.Command);
         }
     }
     return decls;
 }
 private static CMakeItemDeclarations CreateGetXPropertyDeclarations(
     CMakeCommandId id, ParseRequest req, Source source,
     List<string> priorParameters)
 {
     int priorParameterCount =
         priorParameters != null ? priorParameters.Count : 0;
     if (priorParameterCount == CMakeProperties.GetPropertyParameterIndex(id))
     {
         IEnumerable<string> properties = CMakeProperties.GetPropertiesForCommand(id);
         if (properties != null)
         {
             CMakeItemDeclarations decls = new CMakeItemDeclarations();
             decls.AddItems(properties, CMakeItemDeclarations.ItemType.Property);
             if (id == CMakeCommandId.GetDirectoryProperty)
             {
                 // The DIRECTORY keyword can be specified before the property
                 // to set a property of a different directory.
                 decls.AddItem("DIRECTORY",
                     CMakeItemDeclarations.ItemType.Command);
             }
             return decls;
         }
     }
     else if (priorParameterCount == CMakeProperties.GetObjectParameterIndex(id))
     {
         CMakePropertyType type = CMakeProperties.GetPropertyTypeFromCommand(id);
         if (_propObjMethods.ContainsKey(type))
         {
             CMakeItemDeclarations decls = _propObjMethods[type](id, req, source,
                 priorParameters);
             return decls;
         }
     }
     else if (id == CMakeCommandId.GetDirectoryProperty &&
         priorParameterCount == 2 && priorParameters[1] == "DIRECTORY")
     {
         return CreateSubdirectoryDeclarations(id, req, source, priorParameters);
     }
     else if (id == CMakeCommandId.GetDirectoryProperty &&
         priorParameterCount == 3 && priorParameters[1] == "DIRECTORY")
     {
         IEnumerable<string> properties = CMakeProperties.GetPropertiesForCommand(
             CMakeCommandId.GetDirectoryProperty);
         if (properties != null)
         {
             CMakeItemDeclarations decls = new CMakeItemDeclarations();
             decls.AddItems(properties, CMakeItemDeclarations.ItemType.Property);
             return decls;
         }
     }
     return null;
 }
        private static CMakeItemDeclarations CreateSubcommandDeclarations(
            CMakeCommandId id, ParseRequest req, Source source,
            List<string> priorParameters)
        {
            IEnumerable<string> subcommands = CMakeSubcommandMethods.GetSubcommands(id);
            if (subcommands == null)
            {
                return null;
            }

            CMakeItemDeclarations decls = new CMakeItemDeclarations();
            decls.AddItems(subcommands, CMakeItemDeclarations.ItemType.Command);
            return decls;
        }
 private static CMakeItemDeclarations CreateTestDeclarations(CMakeCommandId id,
     ParseRequest req, Source source, List<string> priorParameters)
 {
     List<string> tests = CMakeParsing.ParseForTargetNames(source.GetLines(),
         true);
     CMakeItemDeclarations decls = new CMakeItemDeclarations();
     decls.AddItems(tests, CMakeItemDeclarations.ItemType.Target);
     decls.ExcludeItems(priorParameters);
     return decls;
 }
 private static CMakeItemDeclarations CreateInstalledFileDeclarations(
     CMakeCommandId id, ParseRequest req, Source source,
     List<string> priorParameters)
 {
     List<string> installedFiles = CMakeParsing.ParseForInstalledFiles(
         source.GetLines());
     CMakeItemDeclarations decls = new CMakeItemDeclarations();
     decls.AddItems(installedFiles, CMakeItemDeclarations.ItemType.SourceFile);
     decls.ExcludeItems(priorParameters);
     return decls;
 }
 public override AuthoringScope ParseSource(ParseRequest req)
 {
     CMakeAuthoringScope scope = new CMakeAuthoringScope();
     if (!CMakeSource.IsCMakeFile(req.FileName))
     {
         // Don't do IntelliSense parsing for ordinary text files.
         return scope;
     }
     CMakeSource source = (CMakeSource)GetSource(req.FileName);
     if (req.Sink.HiddenRegions)
     {
         req.Sink.ProcessHiddenRegions = true;
         List<TextSpan> regions = CMakeParsing.ParseForFunctionBodies(
             source.GetLines());
         foreach (TextSpan textSpan in regions)
         {
             req.Sink.AddHiddenRegion(textSpan);
         }
     }
     if (req.Sink.BraceMatching)
     {
         List<CMakeParsing.SpanPair> pairs = null;
         switch ((CMakeToken)req.TokenInfo.Token)
         {
         case CMakeToken.OpenParen:
         case CMakeToken.CloseParen:
             pairs = CMakeParsing.ParseForParens(source.GetLines());
             break;
         case CMakeToken.VariableStart:
         case CMakeToken.VariableStartEnv:
         case CMakeToken.VariableStartCache:
         case CMakeToken.VariableStartSetEnv:
         case CMakeToken.VariableEnd:
             pairs = CMakeParsing.ParseForVariableBraces(source.GetLines(),
                 req.Line);
             break;
         case CMakeToken.GeneratorStart:
         case CMakeToken.GeneratorEnd:
             pairs = CMakeParsing.ParseForGeneratorBraces(source.GetLines(),
                 req.Line);
             break;
         }
         if (pairs != null)
         {
             foreach (CMakeParsing.SpanPair pair in pairs)
             {
                 req.Sink.MatchPair(pair.First, pair.Second, 0);
             }
         }
     }
     if (req.Reason == ParseReason.MemberSelect ||
         req.Reason == ParseReason.MemberSelectAndHighlightBraces ||
         req.Reason == ParseReason.CompleteWord)
     {
         // Set an appropriate declarations object depending on the token that
         // triggered member selection.
         CMakeToken token = (CMakeToken)req.TokenInfo.Token;
         if (token == CMakeToken.String)
         {
             // If the token is a string and the user has began to reference a
             // variable inside the string, treat the string as if it was the
             // appropriate type of variable start token and display member
             // selection for variables.
             string line = source.GetLine(req.Line);
             string tokenText = line.ExtractToken(req.TokenInfo);
             if (tokenText.EndsWith("${"))
             {
                 token = CMakeToken.VariableStart;
             }
             else if (tokenText.EndsWith("$ENV{"))
             {
                 token = CMakeToken.VariableStartEnv;
             }
             else if (tokenText.EndsWith("$CACHE{"))
             {
                 token = CMakeToken.VariableStartCache;
             }
         }
         if (token == CMakeToken.VariableStart)
         {
             List<string> vars = CMakeParsing.ParseForVariables(
                 source.GetLines(), req.Line);
             CMakeVariableDeclarations decls = new CMakeVariableDeclarations(vars,
                 CMakeVariableType.Variable);
             decls.AddItems(source.GetIncludeCacheVariables(),
                 CMakeItemDeclarations.ItemType.Variable);
             string functionName = CMakeParsing.ParseForCurrentFunction(
                 source.GetLines(), req.Line);
             if (functionName != null)
             {
                 List<string> paramNames = CMakeParsing.ParseForParameterNames(
                     source.GetLines(), functionName);
                 paramNames.Add("ARGN");
                 decls.AddItems(paramNames,
                     CMakeItemDeclarations.ItemType.Variable);
             }
             scope.SetDeclarations(decls);
         }
         else if (token == CMakeToken.VariableStartEnv)
         {
             List<string> vars = CMakeParsing.ParseForEnvVariables(
                 source.GetLines());
             CMakeVariableDeclarations decls = new CMakeVariableDeclarations(vars,
                 CMakeVariableType.EnvVariable);
             decls.AddItems(source.GetIncludeCacheEnvVariables(),
                 CMakeItemDeclarations.ItemType.Variable);
             scope.SetDeclarations(decls);
         }
         else if (token == CMakeToken.VariableStartCache)
         {
             List<string> vars = CMakeParsing.ParseForCacheVariables(
                 source.GetLines());
             CMakeVariableDeclarations decls = new CMakeVariableDeclarations(vars,
                 CMakeVariableType.CacheVariable);
             decls.AddItems(source.GetIncludeCacheCacheVariables(),
                 CMakeItemDeclarations.ItemType.Variable);
             scope.SetDeclarations(decls);
         }
         else if (token == CMakeToken.Identifier)
         {
             CMakeParsing.TokenData tokenData;
             CMakeParsing.ParseForToken(source.GetLines(), req.Line,
                 req.TokenInfo.StartIndex, out tokenData);
             if (!tokenData.InParens)
             {
                 CMakeItemDeclarations decls = new CMakeItemDeclarations();
                 IEnumerable<string> commands = CMakeKeywords.GetAllCommands(
                     CMakePackage.Instance.CMakeOptionPage.ShowDeprecated);
                 if (!CMakePackage.Instance.CMakeOptionPage.CommandsLower)
                 {
                     commands = commands.Select(x => x.ToUpper());
                 }
                 decls.AddItems(commands, CMakeItemDeclarations.ItemType.Command);
                 decls.AddItems(
                     CMakeParsing.ParseForFunctionNames(source.GetLines(), false),
                     CMakeItemDeclarations.ItemType.Function);
                 decls.AddItems(
                     CMakeParsing.ParseForFunctionNames(source.GetLines(), true),
                     CMakeItemDeclarations.ItemType.Macro);
                 decls.AddItems(source.GetIncludeCacheFunctions(),
                     CMakeItemDeclarations.ItemType.Function);
                 decls.AddItems(source.GetIncludeCacheMacros(),
                     CMakeItemDeclarations.ItemType.Macro);
                 scope.SetDeclarations(decls);
             }
             else
             {
                 Declarations decls = CMakeDeclarationsFactory.CreateDeclarations(
                     tokenData.Command, req, source,
                     tokenData.ParameterIndex > 0 ? tokenData.PriorParameters : null);
                 scope.SetDeclarations(decls);
             }
         }
         else if (token == CMakeToken.OpenParen)
         {
             CMakeCommandId id = CMakeParsing.ParseForTriggerCommandId(
                 source.GetLines(), req.Line, req.TokenInfo.StartIndex);
             Declarations decls = CMakeDeclarationsFactory.CreateDeclarations(
                 id, req, source);
             scope.SetDeclarations(decls);
         }
         else if (token == CMakeToken.WhiteSpace)
         {
             CMakeParsing.TokenData tokenData;
             CMakeParsing.ParseForToken(source.GetLines(), req.Line,
                 req.TokenInfo.StartIndex, out tokenData);
             Declarations decls = CMakeDeclarationsFactory.CreateDeclarations(
                 tokenData.Command, req, source,
                 tokenData.ParameterIndex > 0 ? tokenData.PriorParameters : null);
             scope.SetDeclarations(decls);
         }
         else if (token == CMakeToken.GeneratorStart)
         {
             scope.SetDeclarations(new CMakeGeneratorDeclarations());
         }
     }
     else if (req.Reason == ParseReason.MethodTip)
     {
         CMakeParsing.ParameterInfoResult result =
             CMakeParsing.ParseForParameterInfo(source.GetLines(), req.Line,
             req.TokenInfo.EndIndex);
         if (result.CommandName != null && result.CommandSpan.HasValue)
         {
             if (result.SubcommandName == null)
             {
                 req.Sink.StartName(result.CommandSpan.Value, result.CommandName);
             }
             else
             {
                 req.Sink.StartName(result.CommandSpan.Value,
                     result.CommandSpan + "(" + result.SubcommandName);
             }
             if (result.BeginSpan.HasValue)
             {
                 req.Sink.StartParameters(result.BeginSpan.Value);
             }
             foreach (TextSpan span in result.SeparatorSpans)
             {
                 req.Sink.NextParameter(span);
             }
             if (result.EndSpan.HasValue)
             {
                 req.Sink.EndParameters(result.EndSpan.Value);
             }
             CMakeCommandId id = CMakeKeywords.GetCommandId(result.CommandName);
             if (id == CMakeCommandId.Unspecified)
             {
                 // If it's a user-defined function or macro, parse to try to find
                 // its parameters.
                 List<string> parameters = CMakeParsing.ParseForParameterNames(
                     source.GetLines(), result.CommandName);
                 if (parameters == null)
                 {
                     parameters = source.GetParametersFromIncludeCache(
                         result.CommandName);
                 }
                 if (parameters != null)
                 {
                     scope.SetMethods(new CMakeUserMethods(result.CommandName,
                         parameters));
                 }
             }
             else
             {
                 scope.SetMethods(CMakeMethods.GetCommandParameters(id,
                     result.SubcommandName));
             }
         }
     }
     else if (req.Reason == ParseReason.Goto)
     {
         scope.SetLines(source.GetLines());
         scope.SetFileName(req.FileName);
     }
     else if (req.Reason == ParseReason.QuickInfo)
     {
         scope.SetLines(source.GetLines());
     }
     else if (req.Reason == ParseReason.Check)
     {
         foreach (ParseForErrorMethod method in _parseForErrorMethods)
         {
             List<CMakeErrorInfo> info = method(source.GetLines());
             foreach (CMakeErrorInfo item in info)
             {
                 CMakeError err = item.ErrorCode;
                 if (_errorStrings.ContainsKey(err) &&
                     (!_enabledMethods.ContainsKey(err) || _enabledMethods[err]()))
                 {
                     req.Sink.AddError(req.FileName, _errorStrings[err], item.Span,
                         item.Warning ? Severity.Warning : Severity.Error);
                 }
             }
         }
         if (CMakePackage.Instance.CMakeOptionPage.ParseIncludedFiles)
         {
             source.BuildIncludeCache(source.GetLines());
             source.UpdateIncludeCache();
             source.PruneIncludeCache();
         }
         else
         {
             source.ClearIncludeCache();
         }
     }
     return scope;
 }