Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
9f646e69
Commit
9f646e69
authored
6 years ago
by
Rustam Vishnyakov
Browse files
Options
Download
Email Patches
Plain Diff
Status bar information, notification and actions (initial)
parent
28457e96
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
plugins/editorconfig/src/org/editorconfig/configmanagement/EditorConfigIndentOptionsProvider.java
+62
-12
...g/configmanagement/EditorConfigIndentOptionsProvider.java
with
62 additions
and
12 deletions
+62
-12
plugins/editorconfig/src/org/editorconfig/configmanagement/EditorConfigIndentOptionsProvider.java
+
62
-
12
View file @
9f646e69
package
org.editorconfig.configmanagement
;
import
com.intellij.ide.actions.ShowSettingsUtilImpl
;
import
com.intellij.openapi.actionSystem.AnAction
;
import
com.intellij.openapi.project.DumbAwareAction
;
import
com.intellij.openapi.project.Project
;
import
com.intellij.openapi.util.Key
;
import
com.intellij.openapi.vfs.VirtualFile
;
import
com.intellij.psi.PsiFile
;
import
com.intellij.psi.codeStyle.CodeStyleSettings
;
import
com.intellij.psi.codeStyle.CommonCodeStyleSettings
;
import
com.intellij.psi.codeStyle.CommonCodeStyleSettings
.IndentOptions
;
import
com.intellij.psi.codeStyle.FileIndentOptionsProvider
;
import
com.intellij.util.containers.ContainerUtil
;
import
org.editorconfig.Utils
;
import
org.editorconfig.core.EditorConfig
;
import
org.editorconfig.plugincomponents.SettingsProviderComponent
;
...
...
@@ -24,9 +29,11 @@ public class EditorConfigIndentOptionsProvider extends FileIndentOptionsProvider
public
static
final
String
tabWidthKey
=
"tab_width"
;
public
static
final
String
indentStyleKey
=
"indent_style"
;
private
static
final
Key
<
Boolean
>
PROJECT_ADVERTISEMENT_FLAG
=
Key
.
create
(
"editor.config.ad.shown"
);
@Nullable
@Override
public
CommonCodeStyleSettings
.
IndentOptions
getIndentOptions
(
@NotNull
CodeStyleSettings
settings
,
@NotNull
PsiFile
psiFile
)
{
public
IndentOptions
getIndentOptions
(
@NotNull
CodeStyleSettings
settings
,
@NotNull
PsiFile
psiFile
)
{
final
VirtualFile
file
=
psiFile
.
getVirtualFile
();
if
(
file
==
null
)
return
null
;
...
...
@@ -39,16 +46,16 @@ public class EditorConfigIndentOptionsProvider extends FileIndentOptionsProvider
return
applyCodeStyleSettings
(
project
,
outPairs
,
file
,
settings
);
}
private
static
CommonCodeStyleSettings
.
IndentOptions
applyCodeStyleSettings
(
Project
project
,
final
List
<
EditorConfig
.
OutPair
>
outPairs
,
final
VirtualFile
file
,
final
CodeStyleSettings
settings
)
{
private
static
IndentOptions
applyCodeStyleSettings
(
Project
project
,
final
List
<
EditorConfig
.
OutPair
>
outPairs
,
final
VirtualFile
file
,
final
CodeStyleSettings
settings
)
{
// Apply indent options
final
String
indentSize
=
Utils
.
configValueForKey
(
outPairs
,
indentSizeKey
);
final
String
continuationIndentSize
=
Utils
.
configValueForKey
(
outPairs
,
continuationSizeKey
);
final
String
tabWidth
=
Utils
.
configValueForKey
(
outPairs
,
tabWidthKey
);
final
String
indentStyle
=
Utils
.
configValueForKey
(
outPairs
,
indentStyleKey
);
final
CommonCodeStyleSettings
.
IndentOptions
indentOptions
=
(
CommonCodeStyleSettings
.
IndentOptions
)
settings
.
getIndentOptions
(
file
.
getFileType
()).
clone
();
final
IndentOptions
indentOptions
=
(
IndentOptions
)
settings
.
getIndentOptions
(
file
.
getFileType
()).
clone
();
if
(
applyIndentOptions
(
project
,
indentOptions
,
indentSize
,
continuationIndentSize
,
tabWidth
,
indentStyle
,
file
.
getCanonicalPath
()))
{
indentOptions
.
setOverrideLanguageOptions
(
true
);
return
indentOptions
;
...
...
@@ -56,7 +63,7 @@ public class EditorConfigIndentOptionsProvider extends FileIndentOptionsProvider
return
null
;
}
private
static
boolean
applyIndentOptions
(
Project
project
,
CommonCodeStyleSettings
.
IndentOptions
indentOptions
,
private
static
boolean
applyIndentOptions
(
Project
project
,
IndentOptions
indentOptions
,
String
indentSize
,
String
continuationIndentSize
,
String
tabWidth
,
String
indentStyle
,
String
filePath
)
{
boolean
changed
=
false
;
...
...
@@ -117,7 +124,7 @@ public class EditorConfigIndentOptionsProvider extends FileIndentOptionsProvider
}
}
private
static
boolean
applyIndentSize
(
final
CommonCodeStyleSettings
.
IndentOptions
indentOptions
,
final
String
indentSize
)
{
private
static
boolean
applyIndentSize
(
final
IndentOptions
indentOptions
,
final
String
indentSize
)
{
try
{
indentOptions
.
INDENT_SIZE
=
Integer
.
parseInt
(
indentSize
);
return
true
;
...
...
@@ -127,7 +134,7 @@ public class EditorConfigIndentOptionsProvider extends FileIndentOptionsProvider
}
}
private
static
boolean
applyContinuationIndentSize
(
final
CommonCodeStyleSettings
.
IndentOptions
indentOptions
,
final
String
continuationIndentSize
)
{
private
static
boolean
applyContinuationIndentSize
(
final
IndentOptions
indentOptions
,
final
String
continuationIndentSize
)
{
try
{
indentOptions
.
CONTINUATION_INDENT_SIZE
=
Integer
.
parseInt
(
continuationIndentSize
);
return
true
;
...
...
@@ -136,7 +143,7 @@ public class EditorConfigIndentOptionsProvider extends FileIndentOptionsProvider
return
false
;
}
}
private
static
boolean
applyTabWidth
(
final
CommonCodeStyleSettings
.
IndentOptions
indentOptions
,
final
String
tabWidth
)
{
private
static
boolean
applyTabWidth
(
final
IndentOptions
indentOptions
,
final
String
tabWidth
)
{
try
{
indentOptions
.
TAB_SIZE
=
Integer
.
parseInt
(
tabWidth
);
return
true
;
...
...
@@ -146,11 +153,54 @@ public class EditorConfigIndentOptionsProvider extends FileIndentOptionsProvider
}
}
private
static
boolean
applyIndentStyle
(
CommonCodeStyleSettings
.
IndentOptions
indentOptions
,
String
indentStyle
)
{
private
static
boolean
applyIndentStyle
(
IndentOptions
indentOptions
,
String
indentStyle
)
{
if
(
indentStyle
.
equals
(
"tab"
)
||
indentStyle
.
equals
(
"space"
))
{
indentOptions
.
USE_TAB_CHARACTER
=
indentStyle
.
equals
(
"tab"
);
return
true
;
}
return
false
;
}
@Override
public
boolean
areActionsAvailable
(
@NotNull
VirtualFile
file
,
@NotNull
IndentOptions
indentOptions
)
{
return
isEditorConfigOptions
(
indentOptions
);
}
@Nullable
@Override
public
AnAction
[]
getActions
(
@NotNull
PsiFile
file
,
@NotNull
IndentOptions
indentOptions
)
{
if
(
isEditorConfigOptions
(
indentOptions
))
{
List
<
AnAction
>
actions
=
ContainerUtil
.
newArrayList
();
actions
.
add
(
DumbAwareAction
.
create
(
"Show settings"
,
e
->
ShowSettingsUtilImpl
.
showSettingsDialog
(
file
.
getProject
(),
"preferences.sourceCode"
,
"EditorConfig"
)
)
);
return
actions
.
toArray
(
AnAction
.
EMPTY_ARRAY
);
}
return
null
;
}
@Nullable
@Override
protected
String
getHint
(
@NotNull
IndentOptions
indentOptions
)
{
return
isEditorConfigOptions
(
indentOptions
)
?
".editorconfig"
:
null
;
}
private
static
boolean
isEditorConfigOptions
(
@NotNull
IndentOptions
indentOptions
)
{
return
indentOptions
.
getFileIndentOptionsProvider
()
instanceof
EditorConfigIndentOptionsProvider
;
}
@Nullable
@Override
public
String
getAdvertisementText
(
@NotNull
PsiFile
psiFile
,
@NotNull
IndentOptions
indentOptions
)
{
Project
project
=
psiFile
.
getProject
();
Boolean
adFlag
=
project
.
getUserData
(
PROJECT_ADVERTISEMENT_FLAG
);
if
(
adFlag
!=
null
&&
adFlag
)
return
null
;
project
.
putUserData
(
PROJECT_ADVERTISEMENT_FLAG
,
true
);
return
"Current indent options are overridden by .editorconfig"
;
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help