Posted in

JetBrains 如何将 AI 融入 IDE:深度解析_AI阅读总结 — 包阅AI

包阅导读总结

1. 关键词:JetBrains AI、IDEs、Code Completion、Code Explanations、Conclusion

2. 总结:本文主要介绍了作者对 JetBrains AI 的试用体验,包括安装配置过程、对代码解释和完成功能的测试,认为其表现出色,虽注册稍繁琐但整体体验良好,预计未来 AI 会成为 IDE 体验的一部分。

3. 主要内容:

– JetBrains AI 试用背景

– 同事对相关产品评价高,作者有机会试用

– 使用 JetBrains AI 的体验

– 专业开发者对 LLM 的需求

– 首次在 Mac 上使用相关 IDE 的设置

– 测试代码解释功能,回答全面准确

– 测试代码完成功能,表现良好且有详细解释

– 结论

– AI 助手表现出色

– 注册稍麻烦但会改变

– 预计未来 AI 会深度融入 IDE 体验

思维导图:

文章地址:https://thenewstack.io/ai-and-ides-walking-through-how-jetbrains-is-approaching-ai/

文章来源:thenewstack.io

作者:David Eastman

发布时间:2024/7/18 13:29

语言:英文

总字数:1490字

预计阅读时间:6分钟

评分:87分

标签:人工智能在集成开发环境中,JetBrains,代码完成,代码解释,开发工具


以下为原文内容

本内容来源于用户推荐转载,旨在分享知识与观点,如有侵权请联系删除 联系邮箱 media@ilingban.com

Editor’s note: our writer, David Eastman, was given free access to JetBrains AI by the company in order to test out its functionality.

Colleagues using Java have always rated IntelliJ, and more recently Rider for C#. So when I was given the opportunity to try JetBrains AI, which is an AI service that refers to itself as “AI Assistant,”I was intrigued. Apparently “It is powered by OpenAI and Google as the primary third-party providers”. I’m not sure trying to match different LLM abilities to certain tasks is a good idea when they are changing so regularly, but not depending on one vendor does make sense.

Now when it comes to using LLMs, professional developers all have slightly varying needs — none of which is “write my code for me.” But the two modes that stand out are code completion and “explain this code,” which is useful for consultants facing an unfamiliar codebase. Generating unit tests is also potentially a fit, even though not taking responsibility for your own unit tests breaks the Agile canon somewhat. I don’t personally rate having examples within the IDE when I could just browse for them — but I know some people do. For instance, most developers have discovered that Time and Date functions can become quite unintuitive; sometimes complex systems can’t be made simpler. Examples of these are very useful.

While this post is a review of the AI Assistant, this will be the first time I’ve had a JetBrains IDE on my Mac, so I have to go through the administration for the first time. I have a “license key” for their AI service, which I will try to graft onto the community edition or equivalent. Whereas ReSharper seems to sit on Visual Studio, Rider is a separate IDE — so I chose that, in order to look at C#. I was hoping the AI service would attach to it; this wasn’t made entirely clear.

I ended up installing a trial version of Rider. Full marks for starting off by importing settings.

In the next section, my question is answered immediately. Hurrah.

This gives me a great deal more trust that customer paths have been considered. It might seem obvious to do this at the start, but I’ve seen enough products that don’t give their own services enough attention. JetBrains emailed me back to get an account once I registered, and I was given a free license for the purposes of testing.

It should be noted that LLM services are very much treated as an add-on, which makes “AI” feel like an add-on. I don’t think this is the fault of the IDE makers at the moment — eventually, this type of offering will exist a bit further back in the OS stack. Right now, we have to wait for the big companies to battle over LLM dominance, which pushes individual users into an explicit consumer position.

Code Explanations

I’ve opened some code from a game project, and we’ll ask for an explanation:

static private List<Archetype> archetypes = new List<Archetype>();

public static List<Archetype> FetchArchetypes() {

if (!archetypes.Any()) {

ArchetypeTemplates tt = BackEnd.DataLoader<ArchetypeTemplates>.LoadGameData(“Archetypes.json”);

foreach (ArchetypeTemplate t in tt.Archetypes) {

archetypes.Add(new Archetype(t));

}

}

return archetypes;

}

An Archetype is just an arbitrary structure from the game. Initially, I read this in as an array from a JSON file, and recreated the structure locally in the list. If the list has already been created, I just pass the list.

So what does the AI think this is doing? It returns a very comprehensive answer, with these two highlights:

  • “At the end, the method returns the Archetypes List which contains Archetype instances created based on the templates from the JSON file. The Archetype class seems to represent a specific archetype in a game and this method is used to populate the list of all archetypes based on the data in the JSON file.”
  • ”In this particular method, it’s worth noting that data loading and object instantiation are only performed when the Archetypes List is empty. This means once the Archetypes have been fetched once, subsequent calls to this method will return the same List without any additional processing. This is a common pattern for instances where loading or object creation is a taxing process and the resulting data doesn’t change over the lifecycle of the application.”

So there are several good things here. It has worked out that the Archetype in question is probably for a game. That’s important — understanding the intention as well as the utility is important when quickly trying to grok code. It has recognized that I’ve used late instantiation, why I’ve used that, and that it is a bonafide pattern.It also understands that reading the JSON file is done elsewhere, but we depend on the input.

I then asked for suggested refactoring, also directly from the context menu:

It suggested separating the loading action into a separate method, to simplify the code. I think almost every developer would agree to that improvement. It could have also have complained about the lack of error detection.

If you want a simple contrast, doing coding creation with JSON persistence using Meta’s Llama 3 wasn’t entirely successful. Mind you, three months is an age in LLM progress.

Code Completion

Let’s try some code completion. I’ll try a similar example to that which I tried for Copilot using the C# FlagsAtribute. From that post: “TheFlagsAttributein C# is used when you want to efficiently store a flag set — that is, a set of boolean values manipulated with bitwise arithmetic.”

Here is a simple example:

[Flags] public enum Pets

{

None = 0,

Dog = 1,

Cat = 2,

Bird = 4,

Rabbit = 8,

Other = 16

}

As long as the flag values go up in binary powers, you can build up a binary flag set. Check that article for a bit more explanation.

I deleted my actual code and asked the assistant to regenerate it with just the signature. I got the purple squiggle and it gave me the option to generate. First, the method to check whether a flag was in the current set. It gave this function body:

public bool CheckFullGameFlags(FullGameFlags flag)

{

return (InGameFullFlags & flag) != 0;

}

Here is what I had originally:

public bool CheckGameFlag(FullGameFlags flag) => (InGameFullFlags.HasFlag(flag));

While it missed the existing C# method HasFlag, it correctly worked out that I wanted to compare the incoming flag with the set. It found the local set InGameFullFlags from the code above.

I then gave it the complimentary signature for SetFullGameFlag. Again, there is enough in the naming conventions for a cue that I want to add the new flag:

I clicked on the squiggle again and used “Implement with AI” and it generated the code below. Again, it came with a full explanation.

void SetFullGameFlag(FullGameFlags flag)

{

InGameFullFlags = InGameFullFlags | flag;

}

This is the same (bar the expression body token ⇒) as what I had:

public void SetGameFlag(FullGameFlags flag) => InGameFullFlags |= flag;

And finally the same for the ClearGameFlag. This just does the bitwise opposite of the set. Again it got this precisely correct.

I would have been happy for the result to be written directly into the editor, or as a code completion, but by writing the assistance in the side panel it came with a good deal of explanation.

Conclusion

All in all I think the AI Assistant performed admirably; for many developers, AI may already be just an expectation for an IDE. Treating AI Assistant as a registration signup is still a minor nuisance, but that will change eventually. I got the whole IDE and AI Assistant up and running pretty quickly, and it ran appreciably quickly.

To some degree, the “Hey! Look! We have AI” is a current business necessity for IDEs as the environment expands and while agreed expectations are still forming. By next year, much of this will exist as part of the IDE experience, just as Cut and Paste does today.

YOUTUBE.COM/THENEWSTACK

Tech moves fast, don’t miss an episode. Subscribe to our YouTubechannel to stream all our podcasts, interviews, demos, and more.

GroupCreated with Sketch.