Skip to content

Commit 28e13e9

Browse files
committed
feat(language): add Rust language profile
Add Rust language profile with syntax queries and language-specific configurations.
1 parent 53531d4 commit 28e13e9

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

src/ProviderLanguageProfile.config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Container } from 'inversify';
33
import { GolangProfile } from './code-context/go/GolangProfile';
44
import { JavaProfile } from './code-context/java/JavaProfile';
55
import { PythonProfile } from './code-context/python/PythonProfile';
6+
import { RustProfile } from './code-context/rust/RustProfile';
67
import { TypeScriptProfile } from './code-context/typescript/TypeScriptProfile';
78
import { ILanguageProfile } from './ProviderTypes';
89

@@ -12,5 +13,6 @@ languageContainer.bind(ILanguageProfile).to(JavaProfile);
1213
languageContainer.bind(ILanguageProfile).to(TypeScriptProfile);
1314
languageContainer.bind(ILanguageProfile).to(GolangProfile);
1415
languageContainer.bind(ILanguageProfile).to(PythonProfile);
16+
languageContainer.bind(ILanguageProfile).to(RustProfile);
1517

1618
export { languageContainer };

src/code-context/rust/RustProfile.ts

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { injectable } from 'inversify';
2+
3+
import rust from '../../code-search/schemas/indexes/rust.scm?raw';
4+
import { LanguageProfile, MemoizedQuery } from '../_base/LanguageProfile';
5+
import { ILanguageServiceProvider } from 'base/common/languages/languageService';
6+
7+
@injectable()
8+
export class RustProfile implements LanguageProfile {
9+
languageIds = ['rust'];
10+
fileExtensions = ['rs'];
11+
grammar = (langService: ILanguageServiceProvider) => langService.getLanguage('rust');
12+
isTestFile = (filePath: string) => filePath.endsWith('test.rs');
13+
scopeQuery = new MemoizedQuery(rust);
14+
hoverableQuery = new MemoizedQuery(`
15+
[(identifier)
16+
(shorthand_field_identifier)
17+
(field_identifier)
18+
(type_identifier)] @hoverable
19+
`);
20+
classQuery = new MemoizedQuery(`
21+
(struct_item (type_identifier) @type_identifier) @type_declaration
22+
`);
23+
methodQuery = new MemoizedQuery(`
24+
(function_item (identifier) @name.definition.method) @definition.method
25+
`);
26+
blockCommentQuery = new MemoizedQuery(`
27+
(block_comment) @docComment
28+
`);
29+
methodIOQuery = new MemoizedQuery(`
30+
(function_item
31+
name: (identifier) @function.identifier
32+
return_type: (type_identifier)? @method-returnType
33+
) @function
34+
`);
35+
structureQuery = new MemoizedQuery(``);
36+
namespaces = [[
37+
// variables
38+
"const",
39+
"function",
40+
"variable",
41+
// types
42+
"struct",
43+
"enum",
44+
"union",
45+
"typedef",
46+
"interface",
47+
// fields
48+
"field",
49+
"enumerator",
50+
// namespacing
51+
"module",
52+
// misc
53+
"label",
54+
"lifetime",
55+
]];
56+
autoSelectInsideParent = [];
57+
builtInTypes = [
58+
// 基本类型
59+
"bool", // 对应 Java 的 boolean
60+
"i8", // 对应 Java 的 byte
61+
"char", // 对应 Java 的 char
62+
"i16", // 对应 Java 的 short
63+
"i32", // 对应 Java 的 int
64+
"i64", // 对应 Java 的 long
65+
"f32", // 对应 Java 的 float
66+
"f64", // 对应 Java 的 double
67+
"()", // 对应 Java 的 void
68+
69+
// 包装类对应类型(Rust 没有直接的包装类型,但以下为常用的类型)
70+
"bool", // 对应 Java 的 Boolean
71+
"i8", // 对应 Java 的 Byte
72+
"char", // 对应 Java 的 Character
73+
"i16", // 对应 Java 的 Short
74+
"i32", // 对应 Java 的 Integer
75+
"i64", // 对应 Java 的 Long
76+
"f32", // 对应 Java 的 Float
77+
"f64", // 对应 Java 的 Double
78+
"String", // 对应 Java 的 String
79+
80+
// 集合类型(Rust 没有直接对应的类型名,但以下为常用的集合类型)
81+
"&[T]", // 对应 Java 的 Array,Rust 中的 slice 引用
82+
"Vec<T>", // 对应 Java 的 List,Rust 中的动态数组
83+
"HashMap<K, V>",// 对应 Java 的 Map,Rust 中的哈希映射
84+
"HashSet<T>", // 对应 Java 的 Set,Rust 中的哈希集合
85+
"Vec<T>", // 对应 Java 的 Collection,Rust 中可用 Vec 代表
86+
"impl Iterator",// 对应 Java 的 Iterable 和 Iterator,Rust 中的 Iterator trait
87+
"impl Iterator",// 对应 Java 的 Stream,Rust 中流式处理可以用 Iterator 实现
88+
"Option<T>", // 对应 Java 的 Optional,Rust 中的 Option 类型
89+
];
90+
}

0 commit comments

Comments
 (0)