Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support inlay hints #7898

Merged
merged 3 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion Python/Product/Common/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Python/Product/Common/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3444,4 +3444,10 @@ Please specify at least one package.</value>
<data name="ImportFormatToolTip" xml:space="preserve">
<value>Defines the default format for import module.</value>
</data>
<data name="InlayHintsFunctionReturnTypesToolTip" xml:space="preserve">
<value>Enable/disable inlay hints for function return types.</value>
</data>
<data name="InlayHintsVariableTypeToolTip" xml:space="preserve">
<value>Enable/disable inlay hints for variable types.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,8 @@ private LanguageServerSettings.PythonSettings GetSettings(Uri scopeUri = null)
extraCommitChars = false,
importFormat = _analysisOptions.ImportFormat,
inlayHints = new LanguageServerSettings.PythonSettings.PythonAnalysisSettings.PythonAnalysisInlayHintsSettings {
variableTypes = false,
functionReturnTypes = false
variableTypes = _analysisOptions.InlayHintsVariableTypes,
functionReturnTypes = _analysisOptions.InlayHintsFunctionReturnTypes
},
taskListTokens = taskListTokens.ToArray()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public sealed class PythonAnalysisOptions {
public string[] ExtraPaths { get; set; }
public bool Indexing { get; set; }
public string ImportFormat { get; set; }
public bool InlayHintsVariableTypes { get; set; }
public bool InlayHintsFunctionReturnTypes {get; set;}

internal PythonAnalysisOptions(PythonToolsService service) {
_service = service;
Expand Down Expand Up @@ -102,6 +104,18 @@ public void Load() {
changed = true;
}

var inlayHintsVariableTypes = _service.LoadBool(nameof(InlayHintsVariableTypes), Category) ?? false;
if (InlayHintsVariableTypes != inlayHintsVariableTypes) {
InlayHintsVariableTypes = inlayHintsVariableTypes;
changed = true;
}

var inlayHintsFunctionReturnTypes = _service.LoadBool(nameof(InlayHintsFunctionReturnTypes), Category) ?? false;
if (InlayHintsFunctionReturnTypes != inlayHintsFunctionReturnTypes) {
InlayHintsFunctionReturnTypes = inlayHintsFunctionReturnTypes;
changed = true;
}

if (changed) {
Changed?.Invoke(this, EventArgs.Empty);
}
Expand All @@ -118,6 +132,8 @@ public void Save() {
changed |= _service.SaveBool(nameof(UseLibraryCodeForTypes), Category, UseLibraryCodeForTypes);
changed |= _service.SaveBool(nameof(Indexing), Category, Indexing);
changed |= _service.SaveString(nameof(ImportFormat), Category, ImportFormat);
changed |= _service.SaveBool(nameof(InlayHintsVariableTypes), Category, InlayHintsVariableTypes);
changed |= _service.SaveBool(nameof(InlayHintsFunctionReturnTypes), Category, InlayHintsFunctionReturnTypes);
if (changed) {
Changed?.Invoke(this, EventArgs.Empty);
}
Expand All @@ -133,6 +149,8 @@ public void Reset() {
UseLibraryCodeForTypes = true;
Indexing = false;
ImportFormat = PylanceImportFormat.Absolute;
InlayHintsVariableTypes = false;
InlayHintsFunctionReturnTypes = false;
Changed?.Invoke(this, EventArgs.Empty);
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public PythonAnalysisOptionsControl() {
_importFormatCombo.Items.Add(Strings.ImportFormatAbsolute);
_importFormatCombo.Items.Add(Strings.ImportFormatRelative);
_importFormatToolTip.SetToolTip(_importFormatCombo, Strings.ImportFormatToolTip);

_inlayHintsVariableTypesToolTip.SetToolTip(_inlayHintsVariableTypes, Strings.InlayHintsVariableTypeToolTip);
_inlayHintsFunctionReturnTypeToolTip.SetToolTip(_inlayHintsFunctionReturnTypes, Strings.InlayHintsFunctionReturnTypesToolTip);
}

internal void SyncControlWithPageSettings(PythonToolsService pyService) {
Expand All @@ -59,6 +62,8 @@ internal void SyncControlWithPageSettings(PythonToolsService pyService) {

_autoSearchPath.Checked = pyService.AnalysisOptions.AutoSearchPaths;
_indexing.Checked = pyService.AnalysisOptions.Indexing;
_inlayHintsVariableTypes.Checked = pyService.AnalysisOptions.InlayHintsVariableTypes;
_inlayHintsFunctionReturnTypes.Checked = pyService.AnalysisOptions.InlayHintsFunctionReturnTypes;
_diagnosticsModeCombo.SelectedIndex =
pyService.AnalysisOptions.DiagnosticMode == PylanceDiagnosticMode.OpenFilesOnly ? 0 : 1;
_importFormatCombo.SelectedIndex =
Expand Down Expand Up @@ -98,6 +103,8 @@ internal void SyncPageWithControlSettings(PythonToolsService pyService) {

pyService.AnalysisOptions.AutoSearchPaths = _autoSearchPath.Checked;
pyService.AnalysisOptions.Indexing = _indexing.Checked;
pyService.AnalysisOptions.InlayHintsVariableTypes = _inlayHintsVariableTypes.Checked;
pyService.AnalysisOptions.InlayHintsFunctionReturnTypes = _inlayHintsFunctionReturnTypes.Checked;
pyService.AnalysisOptions.DiagnosticMode = _diagnosticsModeCombo.SelectedIndex == 0 ?
PylanceDiagnosticMode.OpenFilesOnly : PylanceDiagnosticMode.Workspace;
pyService.AnalysisOptions.ImportFormat = _importFormatCombo.SelectedIndex == 0 ?
Expand Down
Loading
Loading