Skip to content

Code completion sometimes insert "(...)" instead of expected parameter snippets #4027

Closed

Description

@DanTup

Completing here:

Screenshot 2022-06-22 at 15 34 17

Produces this:

Screenshot 2022-06-22 at 15 34 35

Activity

  1. added this to the v3.44.0 milestone on Jun 22, 2022
  2. DanTup commented on Jun 22, 2022

    @DanTup
    MemberAuthor

    This is odd.. the original completion from the server looks like this:

    {
    	"id": 215,
    	"jsonrpc": "2.0",
    	"result": {
    		"isIncomplete": false,
    		"items": [
    			{
    				"data": {
    					"displayUri": "dart:core",
    					"file": "/Users/danny/Desktop/dart_sample/test/refactor.dart",
    					"iLength": 5,
    					"libId": 64,
    					"offset": 15,
    					"rLength": 5,
    					"rOffset": 10
    				},
    				"detail": "(int charCode) → String",
    				"filterText": "String.fromCharCode",
    				"insertText": "String.fromCharCode(${0:charCode})",
    				"insertTextFormat": 2,
    				"kind": 4,
    				"label": "String.fromCharCode(…)",
    				"sortText": "9999893",
    				"textEdit": {
    					"newText": "String.fromCharCode(${0:charCode})",
    					"range": {
    						"end": {
    							"character": 15,
    							"line": 0
    						},
    						"start": {
    							"character": 10,
    							"line": 0
    						}
    					}
    				}
    			}
    		]
    	}
    }

    However the resolve request includes this (note that insertText is missing):

    {
    	"jsonrpc": "2.0",
    	"id": 216,
    	"method": "completionItem/resolve",
    	"params": {
    		"label": "String.fromCharCode(…)",
    		"detail": "(int charCode) → String",
    		"filterText": "String.fromCharCode",
    		"insertTextFormat": 2,
    		"textEdit": {
    			"newText": "String.fromCharCode(${0:charCode})",
    			"range": {
    				"start": {
    					"line": 0,
    					"character": 10
    				},
    				"end": {
    					"line": 0,
    					"character": 15
    				}
    			}
    		},
    		"kind": 4,
    		"sortText": "9999893",
    		"command": {
    			"title": "Suggest",
    			"command": "editor.action.triggerParameterHints"
    		},
    		"data": {
    			"displayUri": "dart:core",
    			"file": "/Users/danny/Desktop/dart_sample/test/refactor.dart",
    			"iLength": 5,
    			"libId": 64,
    			"offset": 15,
    			"rLength": 5,
    			"rOffset": 10
    		}
    	},
    	"clientRequestTime": 1655908025421
    }
  3. DanTup commented on Jun 22, 2022

    @DanTup
    MemberAuthor

    Looks like it's always been the case that the VS Code LSP client is dropping insertText when textEdit is supplied, however we only started doing that with dart-lang/sdk@40e25eb to fix another bug.

  4. DanTup commented on Jun 22, 2022

    @DanTup
    MemberAuthor
  5. DanTup commented on Jul 13, 2022

    @DanTup
    MemberAuthor

    This is happening again / still happening on latest:

    Jul-13-2022 12-32-56

    ==> {
    	"jsonrpc": "2.0",
    	"id": 2578,
    	"method": "completionItem/resolve",
    	"params": {
    		"label": "RegExp(…)",
    		"detail": "(String source, {bool multiLine = false, bool caseSensitive = true, @Since(\"2.4\") bool unicode = false, @Since(\"2.4\") bool dotAll = false}) → RegExp",
    		"filterText": "RegExp",
    		"insertTextFormat": 2,
    		"textEdit": {
    			"newText": "RegExp(${0:source})",
    			"range": {
    				"start": {
    					"line": 78,
    					"character": 51
    				},
    				"end": {
    					"line": 78,
    					"character": 55
    				}
    			}
    		},
    		"kind": 4,
    		"sortText": "9999966",
    		"command": {
    			"title": "Suggest",
    			"command": "editor.action.triggerParameterHints"
    		},
    		"data": {
    			"displayUri": "dart:core",
    			"file": "/Users/danny/Dev/Google/dart-sdk/sdk/pkg/analysis_server/test/lsp/call_hierarchy_test.dart",
    			"iLength": 4,
    			"libId": 69,
    			"offset": 2319,
    			"rLength": 4,
    			"rOffset": 2315
    		}
    	},
    	"clientRequestTime": 1657711930723
    }
    <== {
    	"id": 2578,
    	"jsonrpc": "2.0",
    	"result": {
    		"additionalTextEdits": [],
    		"command": {
    			"command": "editor.action.triggerParameterHints",
    			"title": "Suggest"
    		},
    		"data": {
    			"displayUri": "dart:core",
    			"file": "/Users/danny/Dev/Google/dart-sdk/sdk/pkg/analysis_server/test/lsp/call_hierarchy_test.dart",
    			"iLength": 4,
    			"libId": 69,
    			"offset": 2319,
    			"rLength": 4,
    			"rOffset": 2315
    		},
    		"detail": "(String source, {bool multiLine = false, bool caseSensitive = true, @Since(\"2.4\") bool unicode = false, @Since(\"2.4\") bool dotAll = false}) → RegExp",
    		"documentation": {
    			"kind": "markdown",
    			"value": "A regular expression pattern.\n\nRegular expressions are [Pattern]s, and can as such be used to match strings\nor parts of strings.\n\nDart regular expressions have the same syntax and semantics as\nJavaScript regular expressions. See\n<https://ecma-international.org/ecma-262/9.0/#sec-regexp-regular-expression-objects>\nfor the specification of JavaScript regular expressions.\n\nThe [firstMatch] method is the main implementation method\nthat applies a regular expression to a string\nand returns the first [RegExpMatch].\nAll other methods in [RegExp] can be build from that.\n\nThe following example finds the first match of a regular expression in\na string.\n```dart\nRegExp exp = RegExp(r'(\\w+)');\nString str = 'Parse my string';\nRegExpMatch? match = exp.firstMatch(str);\nprint(match![0]); // \"Parse\"\n```\nUse [allMatches] to look for all matches of a regular expression in\na string.\n\nThe following example finds all matches of a regular expression in\na string.\n```dart\nRegExp exp = RegExp(r'(\\w+)');\nString str = 'Parse my string';\nIterable<RegExpMatch> matches = exp.allMatches(str);\nfor (final m in matches) {\n  print(m[0]);\n}\n```\nThe output of the example is:\n```\nParse\nmy\nstring\n```\n\nNote the use of a _raw string_ (a string prefixed with `r`)\nin the example above. Use a raw string to treat each character in a string\nas a literal character."
    		},
    		"filterText": "RegExp",
    		"insertText": "RegExp(…)",
    		"insertTextFormat": 2,
    		"kind": 4,
    		"label": "RegExp(…)",
    		"sortText": "9999966",
    		"textEdit": {
    			"newText": "RegExp(…)",
    			"range": {
    				"end": {
    					"character": 55,
    					"line": 78
    				},
    				"start": {
    					"character": 51,
    					"line": 78
    				}
    			}
    		}
    	}
    }
  6. reopened this on Jul 13, 2022
  7. DanTup commented on Jul 13, 2022

    @DanTup
    MemberAuthor

    Turns out the SDK I downloaded today is from 21st June and not today. There seems to be an old SDK (without the -release suffix) here:

    https://gsdview.appspot.com/dart-archive/channels/be/raw/latest/sdk/

    Screenshot 2022-07-13 at 12 37 19

    @athomas not sure if you're best person to ask - is it intended that are there some older SDK builds in that folder or should they be removed?

  8. athomas commented on Jul 13, 2022

    @athomas

    @DanTup thanks for highlighting this, I cleaned this up.

  9. DanTup commented on Nov 15, 2022

    @DanTup
    MemberAuthor

    @athomas FYI, there are some files with old dates at https://gsdview.appspot.com/dart-archive/channels/be/raw/latest/sdk/ again. I don't know if they're stuck, or they're old (for example mostly they're md5sum files and I see there are now sha256sum files, so maybe the md5 ones are no longer used, but having them there and not matching the latest versions may be confusing?).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in editorRelates to code editing or language featuresin lsp/analysis serverSomething to be fixed in the Dart analysis serveris bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions