LibreOffice Module basic (master) 1
codecompletecache.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
21#include <iostream>
22#include <officecfg/Office/BasicIDE.hxx>
23#include <officecfg/Office/Common.hxx>
24
25namespace
26{
27CodeCompleteOptions& theCodeCompleteOptions()
28{
29 static CodeCompleteOptions SINGLETON;
30 return SINGLETON;
31}
32}
33
35{
36 bIsAutoCorrectOn = officecfg::Office::BasicIDE::Autocomplete::AutoCorrect::get();
37 bIsAutoCloseParenthesisOn = officecfg::Office::BasicIDE::Autocomplete::AutocloseParenthesis::get();
38 bIsAutoCloseQuotesOn = officecfg::Office::BasicIDE::Autocomplete::AutocloseDoubleQuotes::get();
39 bIsProcedureAutoCompleteOn = officecfg::Office::BasicIDE::Autocomplete::AutocloseProc::get();
40 bIsCodeCompleteOn = officecfg::Office::BasicIDE::Autocomplete::CodeComplete::get();
41 bExtendedTypeDeclarationOn = officecfg::Office::BasicIDE::Autocomplete::UseExtended::get();
42}
43
45{
46 return officecfg::Office::Common::Misc::ExperimentalMode::get() && theCodeCompleteOptions().bIsCodeCompleteOn;
47}
48
50{
51 theCodeCompleteOptions().bIsCodeCompleteOn = b;
52}
53
55{
56 return officecfg::Office::Common::Misc::ExperimentalMode::get() && theCodeCompleteOptions().bExtendedTypeDeclarationOn;
57}
58
60{
61 theCodeCompleteOptions().bExtendedTypeDeclarationOn = b;
62}
63
65{
66 return officecfg::Office::Common::Misc::ExperimentalMode::get() && theCodeCompleteOptions().bIsProcedureAutoCompleteOn;
67}
68
70{
71 theCodeCompleteOptions().bIsProcedureAutoCompleteOn = b;
72}
73
75{
76 return officecfg::Office::Common::Misc::ExperimentalMode::get() && theCodeCompleteOptions().bIsAutoCloseQuotesOn;
77}
78
80{
81 theCodeCompleteOptions().bIsAutoCloseQuotesOn = b;
82}
83
85{
86 return officecfg::Office::Common::Misc::ExperimentalMode::get() && theCodeCompleteOptions().bIsAutoCloseParenthesisOn;
87}
88
90{
91 theCodeCompleteOptions().bIsAutoCloseParenthesisOn = b;
92}
93
95{
96 return officecfg::Office::Common::Misc::ExperimentalMode::get() && theCodeCompleteOptions().bIsAutoCorrectOn;
97}
98
100{
101 theCodeCompleteOptions().bIsAutoCorrectOn = b;
102}
103
104std::ostream& operator<< (std::ostream& aStream, const CodeCompleteDataCache& aCache)
105{
106 aStream << "Global variables" << std::endl;
107 for (auto const& globalVar : aCache.aGlobalVars)
108 {
109 aStream << globalVar.first << "," << globalVar.second << std::endl;
110 }
111 aStream << "Local variables" << std::endl;
112 for (auto const& varScope : aCache.aVarScopes)
113 {
114 aStream << varScope.first << std::endl;
115 CodeCompleteVarTypes aVarTypes = varScope.second;
116 for (auto const& varType : aVarTypes)
117 {
118 aStream << "\t" << varType.first << "," << varType.second << std::endl;
119 }
120 }
121 aStream << "-----------------" << std::endl;
122 return aStream;
123}
124
125void CodeCompleteDataCache::Clear()
126{
127 aVarScopes.clear();
128 aGlobalVars.clear();
129}
130
131void CodeCompleteDataCache::InsertGlobalVar( const OUString& sVarName, const OUString& sVarType )
132{
133 aGlobalVars.emplace( sVarName, sVarType );
134}
135
136void CodeCompleteDataCache::InsertLocalVar( const OUString& sProcName, const OUString& sVarName, const OUString& sVarType )
137{
138 CodeCompleteVarScopes::const_iterator aIt = aVarScopes.find( sProcName );
139 if( aIt == aVarScopes.end() ) //new procedure
140 {
142 aTypes.emplace( sVarName, sVarType );
143 aVarScopes.emplace( sProcName, aTypes );
144 }
145 else
146 {
147 CodeCompleteVarTypes aTypes = aVarScopes[ sProcName ];
148 aTypes.emplace( sVarName, sVarType );
149 aVarScopes[ sProcName ] = aTypes;
150 }
151}
152
153OUString CodeCompleteDataCache::GetVarType( std::u16string_view sVarName ) const
154{
155 for (auto const& varScope : aVarScopes)
156 {
157 CodeCompleteVarTypes aTypes = varScope.second;
158 for (auto const& elem : aTypes)
159 {
160 if( elem.first.equalsIgnoreAsciiCase( sVarName ) )
161 {
162 return elem.second;
163 }
164 }
165 }
166 //not a local, search global scope
167 for (auto const& globalVar : aGlobalVars)
168 {
169 if( globalVar.first.equalsIgnoreAsciiCase( sVarName ) )
170 return globalVar.second;
171 }
172 return OUString(); //not found
173}
174
175OUString CodeCompleteDataCache::GetCorrectCaseVarName( std::u16string_view sVarName, std::u16string_view sActProcName ) const
176{
177 for (auto const& varScope : aVarScopes)
178 {
179 CodeCompleteVarTypes aTypes = varScope.second;
180 for (auto const& elem : aTypes)
181 {
182 if( elem.first.equalsIgnoreAsciiCase( sVarName ) && varScope.first.equalsIgnoreAsciiCase( sActProcName ) )
183 {
184 return elem.first;
185 }
186 }
187 }
188 // search global scope
189 for (auto const& globalVar : aGlobalVars)
190 {
191 if( globalVar.first.equalsIgnoreAsciiCase( sVarName ) )
192 return globalVar.first;
193 }
194 return OUString(); //not found
195}
196
197/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool IsExtendedTypeDeclaration()
static void SetAutoCloseQuotesOn(bool b)
static void SetAutoCloseParenthesisOn(bool b)
static void SetProcedureAutoCompleteOn(bool b)
static bool IsAutoCloseParenthesisOn()
static bool IsAutoCorrectOn()
static void SetAutoCorrectOn(bool b)
static bool IsProcedureAutoCompleteOn()
static void SetCodeCompleteOn(bool b)
static bool IsCodeCompleteOn()
static void SetExtendedTypeDeclaration(bool b)
static bool IsAutoCloseQuotesOn()
std::ostream & operator<<(std::ostream &aStream, const CodeCompleteDataCache &aCache)
std::unordered_map< OUString, OUString > CodeCompleteVarTypes
const SvXMLTokenMapEntry aTypes[]