Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/prompt/common/importStatement.ts
13399 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
export function isImportStatement(line: string, languageId: string): boolean {
7
switch (languageId) {
8
case 'java':
9
return !!line.match(/^\s*import\s/);
10
case 'typescript':
11
case 'typescriptreact':
12
case 'javascript':
13
case 'javascriptreact':
14
return !!line.match(/^\s*import[\s{*]|^\s*[var|const|let].*=\s*require\(/);
15
case 'php':
16
return !!line.match(/^\s*use/);
17
case 'rust':
18
return !!line.match(/^\s*use\s+[\w:{}, ]+\s*(as\s+\w+)?;/);
19
case 'python':
20
return !!line.match(/^\s*from\s+[\w.]+\s+import\s+[\w, *]+$/)
21
|| !!line.match(/^\s*import\s+[\w, ]+$/);
22
default:
23
return false;
24
}
25
}
26
27